perf(evm): optimize interpreter test#353
Draft
starwarfan wants to merge 3 commits intoDTVMStack:mainfrom
Draft
Conversation
… 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):
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):
4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):
5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:
6. Release note