Skip to content

perf(asm): fold the x64 trace slot shift into the byte stride - #554

Open
quake wants to merge 1 commit into
nervosnetwork:release-0.24from
quake:perf/x64-trace-byte-offset-024
Open

quake wants to merge 1 commit into
nervosnetwork:release-0.24from
quake:perf/x64-trace-byte-offset-024

Conversation

@quake

@quake quake commented Nov 30, 2026

Copy link
Copy Markdown
Member

Keep the existing #271 trace slot, (pc >> 2) & 8191, and simplify only the x86-64 calculation of its byte offset. With a 296-byte Trace, the following are identical for every PC, including odd and high addresses:

((pc >> 2) & 8191) * 296 == (pc & (8191 << 2)) * 74

Use the generated stride divided by four, with an assembly-time guard against a future incompatible stride. Both dispatch lookups and the sequential prefetch now compile to and $0x7ffc, %eax; imul $0x4a, %eax, %eax, removing the shift from that dependency chain. No change to the Rust fill path, tag comparison (including the legacy LOAD_PC behavior), table initialization, collisions, charging or prefetch policy. Based directly on release-0.24, independent of other trace PRs.

Validation

  • make test-asm (168 passed), make test (83 passed) on Linux x86-64. Also assembled the file for Darwin x86-64 and Windows x64 (not runtime-tested there).
  • Compared the exact patch against its branch parent 7c15aac: identical cycle-limit outcomes at N-1, N and N+1 for 70 mainnet transactions with externally supplied N.
  • Performance is small and layout-sensitive. On a Ryzen AI 9 HX 370, single worker, 32 balanced rounds of the same 70 transactions, the median paired change in summed TransactionScriptsVerifier::verify time was −0.22% vs the branch parent (round-bootstrap 95% interval −0.51% to +0.01%; parent A/A +0.18%). An earlier fixed-layout v0.24.15 harness comparison on the same corpus measured −1.05%. The instruction reduction is deterministic; the exact source-build timing does not establish a reliable node-level speedup.

@mohanson

mohanson commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

I believe this optimization is equivalent to the original code, but the performance gain seems too small to justify the significant impact on readability.

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