rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

[PERF] Don't spawn so many compilers (3/2) (19m -> 250k)

Open blyxyas opened this issue 7 months ago • 1 comments

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 moves SessionGlobals::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

blyxyas avatar Jun 10 '25 21:06 blyxyas

r? @y21

rustbot has assigned @y21. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

rustbot avatar Jun 10 '25 21:06 rustbot

Weird CI error 🤔 html5ever fails to build?

y21 avatar Jun 20 '25 13:06 y21

Weird CI error 🤔 html5ever fails to build?

This is https://github.com/rust-lang/rust/pull/142785

klensy avatar Jun 20 '25 17:06 klensy