Skip to content

perf(evm): optimize interpreter test#353

Draft
starwarfan wants to merge 3 commits intoDTVMStack:mainfrom
starwarfan:opt-plan
Draft

perf(evm): optimize interpreter test#353
starwarfan wants to merge 3 commits intoDTVMStack:mainfrom
starwarfan:opt-plan

Conversation

@starwarfan
Copy link
Contributor

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

2. What is the scope of this PR (e.g. component or file name):

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains CI/CD configuration changes
  • Contains documentation changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

6. Release note

None

starwarfan and others added 2 commits February 12, 2026 08:36
… cache and instance reuse

Replace per-call overhead (~2.4ms) with two-level module cache and object
reuse, shared by both interpreter and multipass modes:

- L0 cache: code pointer + size comparison (~1ns, 2 integer comparisons)
- L1 cache: code_address + revision map with first/last 256-byte validation
- EVMInstance reuse via resetForNewCall() instead of alloc/free per call
- InterpreterExecContext reuse with deque-to-vector + cross-call caching
- Interpreter fast path bypasses Runtime::callEVMMain for direct dispatch
- Multipass path uses same cache with callEVMMain for JIT execution

Benchmark impact (vs evmone baseline):
- Interpreter: fixed overhead halved from ~2.4ms to ~1.2ms
- Multipass: fixed overhead reduced from ~2.4ms to microseconds
  (e.g. loop_v1: 2.8us, ADD/b0: 15.5us)

Co-authored-by: Cursor <cursoragent@cursor.com>
…e inlining

Replace the switch-based opcode dispatch in the interpreter fast path with
computed goto (GCC/Clang __label__ extension) for better branch prediction
and reduced dispatch overhead.

Key changes:
- Add computed goto dispatch table (256 entries) with per-opcode label targets
- Inline hot opcode logic directly in dispatch targets: arithmetic (ADD, SUB,
  MUL, DIV, etc.), logic (AND, OR, XOR, NOT), comparison (LT, GT, EQ, etc.),
  shifts (SHL, SHR, SAR), stack ops (PUSH0-32, DUP1-16, SWAP1-16, POP),
  and control flow (JUMP, JUMPI, JUMPDEST)
- Use local variables (Pc, sp) for program counter and stack pointer to
  encourage register allocation, syncing back to frame only for complex handlers
- Delegate complex opcodes (memory, storage, calls, creates, logs) to existing
  handler implementations via HANDLER_CALL macro
- Retain original switch-based dispatch as fallback for non-GCC compilers (#else)

Benchmark results (evmone-bench, Release mode, vs evmone baseline interpreter):
- 165 of 167 synth tests faster than evmone baseline
- Average speedup: 5.25x (excluding loop/startup tests)
- Peak speedups: MUL 8.2x, SUB 8.1x, ISZERO/NOT 7.9x, SWAP 6.9x, ADD 6.0x
- Only loop_v1/v2 (tiny 5.8k gas) remain slower due to per-call overhead
@starwarfan starwarfan marked this pull request as draft February 12, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments