Skip to content

perf(traces): make trace identification async to avoid blocking tokio runtime#13431

Open
0xMars42 wants to merge 1 commit intofoundry-rs:masterfrom
0xMars42:perf-async-trace-identification
Open

perf(traces): make trace identification async to avoid blocking tokio runtime#13431
0xMars42 wants to merge 1 commit intofoundry-rs:masterfrom
0xMars42:perf-async-trace-identification

Conversation

@0xMars42
Copy link
Contributor

ExternalIdentifier::identify_addresses() uses foundry_common::block_on(block_in_place(...)) to fetch contract metadata from Etherscan/Sourcify. This blocks a tokio worker thread for the entire duration of the HTTP requests.

6 out of 7 call sites are already in async functions — for example in run_tests_inner(), decoder.identify() calls block_on() while decode_trace_arena().await on the next line uses .await. No reason to pay for block_in_place when we can just await the futures directly.

This makes TraceIdentifier::identify_addresses() async via #[async_trait] (already used in the same file for ExternalFetcherT) and drops the block_on() wrapper in ExternalIdentifier. The one sync caller (load_contracts in lib.rs) keeps block_on() since it only ever gets a LocalTraceIdentifier which is pure CPU anyway.

Fixes #12714, addresses #3236. Supersedes #12905.

… runtime

`ExternalIdentifier::identify_addresses()` used `foundry_common::block_on()`
to synchronously wait for Etherscan/Sourcify HTTP requests during trace
rendering. Since every caller is already in an async context, this
unnecessarily blocked tokio worker threads via `block_in_place`.

Convert the `TraceIdentifier` trait to async (using `async_trait`, already
a dependency and already used in the same file for `ExternalFetcherT`),
remove the `block_on` wrapper in `ExternalIdentifier`, and add `.await`
at all call sites.

This lets HTTP requests execute natively on the tokio runtime without
blocking worker threads, improving responsiveness when processing
multiple traces concurrently.
@0xMars42 0xMars42 force-pushed the perf-async-trace-identification branch from 65ec814 to 11f60f6 Compare February 13, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

perf(forge): printing traces is too slow due to external lookups

1 participant