Repository navigation
Conversation
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## perf/traces-top-of-stack #1541 +/- ##
============================================================
+ Coverage 80.13% 80.14% +0.01%
============================================================
Files 445 445
Lines 76572 76592 +20
Branches 76572 76592 +20
============================================================
+ Hits 61358 61383 +25
+ Misses 13091 13087 -4
+ Partials 2123 2122 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
16dcddd to
f25666b
Compare
5233d06 to
8709235
Compare
Writing captured tops into the arena's steps at collect time costs one heap allocation per step (a single-element Box<[U256]> snapshot) plus an ordering DFS on every transaction, whether or not the traces are ever read. Consumers that enable includeCallTraces without attaching VM listeners - the scenario benchmark, and any HH2 run without solidity-coverage-style plugins - paid it for nothing. Instead, collect()/take() now return the arena bundled with the raw captured tops (edr_solidity::tracing::CallTraces), and the bundle travels to the napi Response as-is. Response.traces() zips the tops with its existing depth-first step walk, materializing JS values directly - the only consumer of per-step stacks in non-verbose mode. Transactions whose traces are never marshalled now pay only the per-step U256 copy at capture time. The zip stays aligned with capture order across the walk's quirks: the skipped leading STOP step still consumes a top, and children skipped by should_skip_call have no steps by definition. Alignment is debug_assert-ed at the root; running out of tops degrades to steps without a stack, as before. The write_stack_tops unit tests move to the napi marshal layer as tests of the zip; the edr_napi provider.ts trace tests remain the end-to-end contract and pass unchanged, as does the JS-visible shape (typings unchanged).
Mirrors the setVerboseTracing plumbing: a setIncludeCallTraces napi method through SyncProvider, Provider, and ProviderData, mutating the observability config used for subsequent requests. Traces that are not included are never collected (no arenas retained in responses, no top-of-stack capture), so a consumer that knows whether anything will read traces() - like Hardhat 2's trace-event bridge, which already computes exactly that from its VM event listener counts - can keep collection off while there are no readers instead of paying for traces statically.
The hardhat patch enabled includeCallTraces: All statically, so every transaction paid for trace collection (top-of-stack capture, arenas retained in responses until GC) even when no plugin ever consumes the vm trace events - the scenario benchmark's configuration, and any run without solidity-coverage-style plugins. The wrapper already computes whether traces are needed from its VM event listener counts; evaluate that before dispatching the request and toggle the provider's includeCallTraces via the new setter when it changes. In practice that is one napi call per process, since listeners attach at plugin setup. hardhat_reset recreates the inner provider from the creation-time config, so the tracked state resets with it.
8709235 to
b8a0351
Compare
f25666b to
b5184e1
Compare
Follow-up to #1536, resolving the residual benchmark alert (1.12–1.20x on four scenarios) by only paying for trace collection when something consumes the traces.
Claude summary
Problem
#1536 replaced full-stack clones with top-of-stack capture, but the
edr-benchmarkruns on it still alerted at 1.12–1.28x against the traces-off baseline. The residual cost ofincludeCallTraces: Allwas paid statically on every transaction, even when nothing ever readstraces():Box<[U256]>stack snapshots written into the arena at collect time, plus an ordering DFS per transaction;Responseand retained until JS GC, instead of being dropped at filter time like theNonepath.The scenario benchmark — like any Hardhat 2 run without solidity-coverage-style plugins — never reads the traces it was paying for. Hardhat 2 already computes exactly the right signal (
needsTraces, from its VM event listener counts); it just had no way to act on it.Approach (one commit each)
collect()/take()return the arena bundled with the raw captured tops (edr_solidity::tracing::CallTraces); nothing is written into the arena's steps.Response.traces()— the only consumer of per-step stacks in non-verbose mode — zips the tops with its existing depth-first step walk, materializing JS values directly. The walk's quirks are handled explicitly: the skipped leadingSTOPstep still consumes a captured value, and children skipped byshould_skip_callhave no steps by definition. This removes the per-step allocations and the DFS from every transaction whose traces are never marshalled. Verified on the benchmark: theAll Scenariosaggregate, synthetix, and rocketpool dropped below the alert threshold; seaport 1.28→1.13, openzeppelin 1.26→1.17, uniswap-v3-core 1.24→1.20 (step-dense, dominated by the remaining capture cost).setIncludeCallTraces(). A runtime toggle forincludeCallTraces, mirroring thesetVerboseTracingplumbing throughSyncProvider/Provider/ProviderData. Traces that are not included are never collected: no arenas retained in responses and no top-of-stack capture for subsequent requests.IncludeTraces.Allstatically at provider creation. Instead the wrapper evaluates the bridge's existingneedsTraceslistener check before dispatching each request and toggles the setter when the value changes — in practice one napi call per process, since listeners attach at plugin setup.hardhat_resetrecreates the inner provider from the creation-time config, so the tracked state resets with it. The same change is mirrored on the Hardhat 2 source branch backing HH2: Port hardhat-network provider to the current EDR API and restore trace events hardhat#8422 (the patch source stays byte-identical to that branch).With all three, the scenario benchmark exercises the true
Nonepath — the same work as the stored baseline — so the gate should go green, while coverage-style consumers pay capture + marshal only while actually listening.Anticipated questions
StackSnapshotType::Topupstream (feat: add top-of-stack snapshot type paradigmxyz/revm-inspectors#468)? Yes. UpstreamTopmaterializes a boxed single-element snapshot per step during execution — exactly the allocation the lazy path avoids — so migrating to it would now be a regression. Emit events in debug_traceTransaction and debug_traceCall #468 remains useful for otherrevm-inspectorsconsumers.traces(); Hardhat 2's wrapper is the one place that knows (its VM event listener counts). Hardhat 3 consumers configureincludeCallTracesexplicitly per provider, unchanged.Testing
write_stack_topsunit tests moved to the napi marshal layer as tests of the zip: execution order across nested call frames, the skipped-leading-STOPalignment, and the recorded-stack fallback when no tops were captured.edr_napitest:setIncludeCallTracestoggles take effect for subsequent requests — traces absent by default, present (with correct per-step tops) after enabling, absent again after disabling.CALLcontract test and the feat: add backwards compatibility forResponse::traces#1301 trace tests pass unchanged; typings regenerated (setIncludeCallTracesis the only addition).hardhat-tests: the trace-event-bridge spec still emitsstep/beforeMessage/afterMessage— proving the listeners → toggle → collect → bridge chain end-to-end — and theevm/hardhatmodules pass against the updated patch.