[PERF] Don't spawn so many compilers (3/2) (19m -> 250k) #15030
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.
Optimize
needless_doctest_main
, make it short-circuit, make sure that we don't spin up a new compiler on EVERY code block.The old implementation was creating a new compiler, new parser, new thread, new SessionGlobals, new everything for each code block. No matter if they actually didn't even contain
fn main()
or anything relevant.On callgrind, seems that we're reducing about a 6.7242% de cycle count (which turns out to be a 38 million instruction difference, great!). Benchmarked in
bumpalo-3.16.0
. Also on bumpalo we spawn 78 less threads. This movesSessionGlobals::new
from the top time-consuming function by itself in some benchmarks, into one not even in the top 500.Also, populate the test files.
changelog:[
needless_doctest_main
]: Avoid spawning so many threads in unnecessary circumstances