Improve compile times by using type erasure + a worrying look into the future of rustc - #267
Improve compile times by using type erasure + a worrying look into the future of rustc#267HugoPeters1024 wants to merge 1 commit into
Conversation
|
Welcome, new contributor! Please make sure you have read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
|
Very interesting finding! 😮 I need more evidence and data as to what is causing the regression. Intuitively I would have guessed it is caused by the large amounts of code generated by the parser (lalrpop) in Even with your fix, going from 5s to 43s is not acceptable. |
|
Here are my numbers:
My specs:
So for me, your PR does improve compile times significantly, but I could not reproduce your issue as the |
cargo 1.100.0-nightly (e8cb624d5 2026-08-22) |
|
just a reminder for anyone else wanting to post timings, each run needs to be from clean state (after it is probably already forced because a change in solver might invalidate all of the artifacts, but just in case |
|
Hey that's surprising.... Looks like there is one variable that I forgot to report: the exact rustc revision I was working with. I thought I was working off the latest main, but I was a week or so behind. And indeed, it appears this issue is real, but also has been patched very recently:
I suppose that puts a nail in the coffin of this PR. It's an interesting case study, but 0.3s compile time wins are almost certainly not worth the cost of dynamic dispatch. Thanks for thinking along everyone! |
While playing around with rustc's upcoming new trait solver on bevy , I noticed that it improved the performance of some of Bevy's subcrates, but the total compilation time was much worse due to
wesl.Turns out that
weslinteracts surprisingly bad with this new solver. I was able to find very simple patch that improves this a bunch, as well as improves the compile times under the legacy solver:naga-extA critical read might say that the next solver is still a major performance setback when it comes to this crate. And they would be right! I will also report this regression upstream (DONE HERE) at rustc in the hope that they can use
weslas a case study before rolling out the new solver as the default.Tradeoffs
I believe that these boxes do incur a slight runtime cost due to dynamic dispatch. Under the legacy solver, this patch not an extremely convincing win.
Benchmark command
Timings were collected from clean target directories using Cargo's timing
report. The new-solver measurement used a locally built nightly/dev compiler
that supports
-Znext-solver.So what's next?
Not sure, tbh. I just wanted to get this out there.