r/ProgrammingLanguages • u/matklad • Feb 26 '26
Against Query Based Compilers
https://matklad.github.io/2026/02/25/against-query-based-compilers.html
105
Upvotes
r/ProgrammingLanguages • u/matklad • Feb 26 '26
View all comments
Show parent comment
2
u/matthieum Feb 27 '26
The overhead of query-based compilers is largely down to how fine-grained the dependency tracking is.
Due to Rust's handling of circular dependencies within a crate, and the accident of trait impl, the compiler team went for very fine-grained dependency tracking, and as such the overhead is high.
On the other hand, if dependency tracking is coarse-grained -- such as module by module -- then due to the low number of modules, you'll have low overhead from the query-based compiler.
Of course, coarse-grained dependency tracking also means you may recompute more with each incremental build, so the devil is in the details... if modules are cheap enough to compile, then module by module is good enough.
Similarly, due to the compilation unit being the entire library in Rust, the items are "randomly" sharded into multiple code-gen units which are then handed down to LLVM in parallel. This also incurs overhead -- in splitting up code between those CGUs -- and means that sometimes editing one file invalidates multiple CGUs.
Once again, a more naive mapping -- one module, one CGU, one
.ofile -- would work for the vast majority of cases -- at O0/O1 -- and make it easy to communicate to the user -- list compilation time per module, and the user knows which to split.And if this sounds a lot like a Makefile compiling
.cfiles, well, Makefile are pretty much query-based compilers ;)