Repository navigation
perf: record only the top of the stack for non-verbose raw traces - #1544
Conversation
Replaces the StackSnapshotType::Full snapshots introduced for Response::traces back-compat, which clone the entire EVM stack (up to 1024 words) on every step, with the new StackSnapshotType::Top from paradigmxyz/revm-inspectors#468: a single-element (or empty) snapshot per step, matching what non-verbose consumers read via step.stack.last(). When includeCallTraces is None (the Hardhat 3 default), snapshots are skipped entirely: the stack-trace and internal-OOG paths read pcs and statuses, never step stacks. Until revm-inspectors#468 is released and EDR is on its revm major, revm-inspectors is consumed from a fork branch that backports the upstream PR commit onto the 0.39.0 release (nebasuke/revm-inspectors@feat/top-of-stack-snapshot-0.39); the dependency then reverts to crates.io with a version bump. The integration test is carried over from the superseded hand-rolled capture approach (#1536).
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## feat/tracing-back-compat #1544 +/- ##
=========================================================
Coverage 80.10% 80.10%
=========================================================
Files 445 445
Lines 76436 76439 +3
Branches 76436 76439 +3
=========================================================
+ Hits 61228 61233 +5
+ Misses 13086 13085 -1
+ Partials 2122 2121 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
The code itself looks good. Thank you for this fix!
I did a local profiling run to analyse the remaining performance regression. The fix in this PR covers the worst offenders:
- memory increase to store full stacks (can cause OOM)
- performance regression due to increase mem copy & free load
With Claude's help, I analysed the performance (samples collected with perf) of EDR versions with:
includeCallTraces: All- prior to fix
- after your fix
includeCallTraces: None
The seaport scenario illustrates the regression and fix well:
| mechanism | baseline | regressed | fixed |
|---|---|---|---|
| TracingInspector::start_step incl. snapshot allocs | 0.6s | 2.6s | 0.7s |
| Arena free when napi Response drops | ~0 | 1.2s | 0.5s |
| mimalloc page management churn | ~0 | 1.0s | 0.1s |
| wall time | 5.51s | 12.67s | 7.47s |
It also shows that even the baseline is spending a lot of time in TracingInspector::start_step. I'll continue investigating differences compared to TraceCollector and address those on the existing PR.
On top of #1301 (
feat/tracing-back-compat) to resolve the benchmark regression of up to 2.45x reported there. Supersedes #1536: this directly usesStackSnapshotType::Top(paradigmxyz/revm-inspectors#468) from a fork branch that backports it onto the 0.39.0 release EDR already pins.Note there is an expected performance regression compared to not producing traces, see below. This holds only for Hardhat 2.
All Scenarios245310.748094ms214303.369506ms1.14neptune-mutual-blue-protocol_8db648025903.104518ms22167.746617ms1.17openzeppelin-contracts_0a5fba7a11628.837737000002ms9068.634355999999ms1.28rocketpool_6a9dbfd814754.833111ms13019.832804000001ms1.13safe-contracts_914d0f8730.062472ms657.7373329999999ms1.11seaport_585b2ef85946.402571ms4910.134137999999ms1.21synthetix_9a3a109f181693.82570000002ms160506.680113ms1.13uniswap-v3-core_d8b1c634653.681985ms3972.6041450000002ms1.17Claude summary
Problem
To expose the top of the stack through the non-verbose
Response::traces()output, #1301 setsStackSnapshotType::Full, which clones the entire EVM stack (up to 1024 words) on every step of every transaction. The cost is paid unconditionally — even when the arena is discarded (includeCallTracesdefaults toIncludeTraces::None, the Hardhat 3 default). The consumer only ever readsstep.stack.last()in non-verbose mode, and no releasedrevm-inspectors(0.33–0.41) offers a top-of-stack-only snapshot type.Approach
Use the real thing:
StackSnapshotType::Topfrom paradigmxyz/revm-inspectors#468 records a single-element (or empty) snapshot per step — oneU256copy instead of a full stack clone — into the samestep.stackfield, so.last()consumers are unchanged. WhenincludeCallTracesisNone, snapshots are skipped entirely: the stack-trace and internal-OOG paths read pcs and statuses, never step stacks.Since upstream #468 targets the revm-41 line and EDR pins revm-inspectors 0.39.0 / revm 38, the dependency temporarily points at
nebasuke/revm-inspectorsbranchfeat/top-of-stack-snapshot-0.39— the upstream PR commit cherry-picked onto the 0.39.0 release commit (applied cleanly, full test suite green including the two new stack snapshot tests). Once #468 is released and EDR moves to its revm major, the dependency reverts to crates.io with a version bump and this PR's diff shrinks to the config gating.Resulting cost per configuration:
includeCallTraces: None(Hardhat 3 default)mainincludeCallTraces: All, non-verbose (Hardhat 2)U256copy per step (the historical baseline)all())Changes
Cargo.toml/Cargo.lock:revm-inspectorsfrom the fork branch, pinned in the lockfile to the backport commit. Git sources are skipped by cargo-cooldown-check; nothing else re-resolved.crates/edr_provider/src/observability.rs: non-verbose tracing config selectsStackSnapshotType::Top, orStackSnapshotType::Nonewhen traces can't be included in responses.crates/edr_napi/test/provider.ts: nested-call-frames top-of-stack integration test carried over from perf: capture only the top of the stack for non-verbose raw traces #1536; step semantics (Some([])for an empty stack,Some([top])otherwise) are additionally pinned down by the fork's owntests/it/stack.rs.Testing
cargo testgreen (30 integration tests +test_top_stack_snapshots+test_top_stack_snapshots_match_the_top_of_full_snapshots).cargo check --no-default-features(workspace),cargo test --all-features -p edr_solidity -p edr_provider(remote-fork tests requiringALCHEMY_URLexcluded locally), and the napi mocha tests matching "top of the stack" against a rebuilt binding.