Skip to content

perf: use a single trace cursor in x86-64 ASM dispatch - #550

Open
quake wants to merge 1 commit into
nervosnetwork:developfrom
quake:perf/x64-trace-cursor
Open

quake wants to merge 1 commit into
nervosnetwork:developfrom
quake:perf/x64-trace-cursor

Conversation

@quake

@quake quake commented Nov 29, 2026

Copy link
Copy Markdown
Member

The x86-64 dispatcher advances two pointers in lockstep on every decoded instruction. The trace is already interleaved: the handler address is the word immediately before the instruction. Load both through the instruction cursor, preserving the existing load order and indirect jump.

Use the freed register (%r8) for the guest PC. Load it on entry and write it back at the common ASM exit, including on errors, syscalls and trace misses. The existing call wrapper already saves/restores this register around lazy frame initialization. This does not change the trace layout, decoder, prefetching, or cycle accounting. No cross-VM cache or AOT is involved.

Local measurements (Linux x86-64, Ryzen AI 9 HX 370, pinned core, release build):

  • V2 ASM with MOP and estimate_cycles, running the release-0.24:benches/data/secp256k1_bench ELF with the arguments from vm_benchmark.rs. Fresh machine + ELF load + run; 30 warmups and 300 measured runs per process. Across seven alternating before/after pairs, the median of process medians went from 1.950 ms to 1.927 ms. Exit code 0 and 1,148,317 cycles on both builds. This is a small, workload-specific difference; individual runs overlap.

Validation

  • make test-asm: 171 tests passed on Linux x86-64.
  • make test-asm-chaos: tests/test_artifact.rs::test_artifact fails at the same assertion on the unmodified base and this branch. The other chaos tests passed.
  • Cross-assembled the modified source for macOS and Windows x86-64 with Clang; not runtime-tested on those platforms.

@mohanson

Copy link
Copy Markdown
Collaborator

I believe this PR is correct in terms of its logic, but the performance improvement is too small. To be on the safe side, this PR will not be merged for the time being.

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.

2 participants