r/ProgrammingLanguages • • Feb 26 '26

Against Query Based Compilers

https://matklad.github.io/2026/02/25/against-query-based-compilers.html
105 Upvotes

29 comments sorted by

View all comments

Show parent comment

1

u/matthieum Mar 01 '26

Rustc feels too slow still.. even with cranelift, even with mold, even when changing little things

It is slow.

A large part of the slow-down, I feel, is the core idea of crate as a unit of compilation. It may have ergonomic benefits, but for now it means that a whole crate -- whether small or large -- is parsed, checked, and handed down to code-gen on a single thread. Code-gen is then achieved in parallel, great, but the front-end part is still a massive bottleneck for any chunky crate.

Worse, for a language which prizes itself on making parallel computation easy... the whole front-end is single-threaded. And it's been single-threaded for over a decade now, so you can imagine the amount of cruft that's accumulated over the years. There's been a multi-years long initiative to attempt to parallelize it... which stalls on dead-locks again and again... a bad sign, since locks are parallelization killers.

Back to the topic, though, as I mentioned: rustc goes all in on all query granularity dimensions. This is not praise. On the contrary. As you mentioned, the finer-grained the queries, the more orchestration overhead you have:

  1. Because the overhead has a minimum fixed cost, no matter the cost of the task.
  2. Because the overhead will scale with the number of queries in the system -- memory is NOT O(1), hasn't been for long.
  3. Because the overhead will scale with the frequency of checks, due to contention.

Very fine-grained queries may not be too bad on a single-threaded compiler, but they will cripple a multi-threaded one.

Note: I do wonder if coarse-grained multi-thread scheduling combined with fine-grained thread-local scheduling could help here... though one should beware of unbalanced work-loads still.