Skip to content

perf(vm): hoist allowDynamicEnergy out of the opcode loop#6858

Merged
CodeNinjaEvan merged 1 commit into
tronprotocol:release_v4.8.2from
yanghang8612:vm-perf-dynamic-energy-482
Jun 27, 2026
Merged

perf(vm): hoist allowDynamicEnergy out of the opcode loop#6858
CodeNinjaEvan merged 1 commit into
tronprotocol:release_v4.8.2from
yanghang8612:vm-perf-dynamic-energy-482

Conversation

@yanghang8612

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #6857. That PR routed every VMConfig getter through a thread-local current() (process-global snapshot + per-constant-call override). VM.play reads VMConfig.allowDynamicEnergy() once per executed opcode, so after #6857 each opcode now pays a ThreadLocal.get() on the block-processing hot path, where before it was a plain, inlinable static read.

CPU profiling (release_v4.8.2 vs master, same workload) shows new hot frames on 4.8.2 that are absent on master:

  • org.tron.core.vm.config.VMConfig.current
  • java.lang.ThreadLocal$ThreadLocalMap.getEntryAfterMiss — the localSnapshot lookup falls onto the linear-probe miss path on the block thread, which never installs a thread-local view.

The flag is VM config: it is loaded once in VMActuator.validate and is immutable for the whole execution. Reading it once per execution instead of once per opcode is therefore semantically identical and restores the pre-#6857 hot-path cost.

vmTrace() is intentionally left untouched — it was not migrated to the snapshot in #6857 and is still a plain static read.

Test

  • :actuator:compileJava green.
  • org.tron.common.runtime.vm.OperationsTest green (exercises the VM.play loop including dynamic-energy / suicide / vote-witness paths).

@github-actions github-actions Bot requested a review from CodeNinjaEvan June 26, 2026 11:50
@CodeNinjaEvan CodeNinjaEvan merged commit f15c1ea into tronprotocol:release_v4.8.2 Jun 27, 2026
12 checks passed
@halibobo1205 halibobo1205 added the topic:vm VM, smart contract label Jun 27, 2026
@halibobo1205 halibobo1205 added this to the GreatVoyage-v4.8.2 milestone Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:vm VM, smart contract

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants