r/rust • u/janameow • 2d ago
Optimizing rustc's next trail solver
https://donsz.nl/blog/optimizing-rustcs-next-trait-solverThe next rust trait solver, a large subsystem of the rust compiler that we've been trying to replace, will finally land in rust 1.102.0. In the last stages, before stabilizing it, its performance was a major blocker. But what is "a trait solver"? And why is its performance a problem? My goal for this blog post is to answer those questions in a way where you don't need any prior knowledge. I think discussions of the trait solver can quickly become quite involved, and daunting. So here, we'll start from the very basics!
This is a writeup of my eurorust 2026 talk of the same name, that I gave on October 15, 2026
30
u/janameow 2d ago
Note, this was previously posted here as just the video by eurorust. See https://www.reddit.com/r/rust/comments/1y4adhs/optimizing_rustcs_next_trait_solver_jana/
86
u/noop_noob 2d ago
We love solving trails.
2
u/kevinbaiv 2d ago
The opaque type retry path is what I want to understand better: when an answer was recorded assuming opaque types don't matter and the retry says otherwise, do you evict the entry or keep both keyed by the recorded state? And does the hit rate in the chart count those speculative answers as hits? Either way, 200 billion cycles down to 7 billion on wg-grammar is the kind of number I want to see in more optimization writeups.
5
u/popzxc 2d ago
Loved the talk, and good to see it in text format too!
4
u/ebkalderon amethyst · renderdoc-rs · tower-lsp · cargo2nix 2d ago
Fantastic talk and writeup! I watched the Eurorust recording yesterday and enjoyed it very much. One question I still have for the OP: would you mind elaborating further on the Q&A question about negative trait bounds and why you believe that feature will never be stabilized? I'd love to understand the fundamental limitations a bit better. Thanks again for sharing.
3
u/scook0 2d ago
I’ve encountered some of these trait-solver details (like canonicalization) while cleaning up the rustc query system, but I never had much context for what they were actually doing, so it’s neat to see more elaboration in this post.
2
u/spin81 2d ago
I don't have time to read the post now as I'm supposed to be working, but will check it out as it's tailored just for me in terms of previous knowledge!
I can see why this would be an important way to improve rustc performance, I bet in big projects there's a LOT of trait solving the compiler has to do and that it can get pretty complex in terms of the Cartesian products of possibilities there can be. Wanted to thank you for sharing!
Unrelatedly I am thinking of doing Advent of Code in a language I don't yet know and I saw Prolog mentioned in the post. Can anyone say if Prolog is a fun one to do AoC in for a Prolog noob?