Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: spawn tokio runtime once #5263

Merged
merged 4 commits into from
Jul 1, 2023
Merged

Conversation

DaniPopes
Copy link
Member

@DaniPopes DaniPopes commented Jul 1, 2023

Motivation

We're spawning thousands of tokio runtimes which accounts for ~50-60% of the time spent in the main thread. These calls happen both in parallel (where there is almost no gain), and in the end clean up (which speeds it up significantly). This happens in RuntimeOrHandle::new().block_on(...) which spawns a new tokio runtime to run a single future, then drops it

Before (41% + 17%):

image

After (no recorded calls):

image

Solution

Make test functions async and create a runtime in the CLI dispatch

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg, finally.

I have been dreading this for so long because this touches the test runner API.

tysm for doing this!!

this pulls in openssl again for apparently no reason, no idea why, perhaps the rustls feature? idk

forge/Cargo.toml Outdated Show resolved Hide resolved
@mattsse mattsse added the T-perf Type: performance label Jul 1, 2023
@mattsse
Copy link
Member

mattsse commented Jul 1, 2023

some failing tests, because of blocking calls I think

@DaniPopes
Copy link
Member Author

DaniPopes commented Jul 1, 2023

Same as openssl, any clue how to fix? b325876
image

@mattsse
Copy link
Member

mattsse commented Jul 1, 2023

the only cargo change I'm seeing is the rustls feature

https://github.com/foundry-rs/foundry/pull/5263/files#diff-d9d5adf55ead8df6e41955ab981380acb217885a608393d800515cb51a769c87

maybe try after reverting this, no idea why this would cause it though

.github/workflows/deny.yml Outdated Show resolved Hide resolved
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tysm!

step by step we're improving the test runner

@mattsse mattsse merged commit c7a3c18 into foundry-rs:master Jul 1, 2023
@DaniPopes DaniPopes deleted the perf/runtimes branch July 1, 2023 14:31
This was referenced Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-perf Type: performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants