perf(traces): make trace identification async to avoid blocking tokio runtime#13431
Open
0xMars42 wants to merge 1 commit intofoundry-rs:masterfrom
Open
perf(traces): make trace identification async to avoid blocking tokio runtime#134310xMars42 wants to merge 1 commit intofoundry-rs:masterfrom
0xMars42 wants to merge 1 commit intofoundry-rs:masterfrom
Conversation
… 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.
65ec814 to
11f60f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ExternalIdentifier::identify_addresses()usesfoundry_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()callsblock_on()whiledecode_trace_arena().awaiton the next line uses.await. No reason to pay forblock_in_placewhen we can just await the futures directly.This makes
TraceIdentifier::identify_addresses()async via#[async_trait](already used in the same file forExternalFetcherT) and drops theblock_on()wrapper inExternalIdentifier. The one sync caller (load_contractsin lib.rs) keepsblock_on()since it only ever gets aLocalTraceIdentifierwhich is pure CPU anyway.Fixes #12714, addresses #3236. Supersedes #12905.