6 ms·
Incremental compilation! And it's only going to incremental-er from here, as the compiler learns how to cache more and more sorts of interim artifacts to avoid
by kibwen 9y ago
Incremental compilation! And it's only going to incremental-er from here, as the compiler learns how to cache more and more sorts of interim artifacts to avoid redundant work. Though I think the wording in the OP is a bit off:
> Historically, the compiler has compiled your entire project, no matter how little you’ve changed the code.
This isn't quite correct. When you change the code in a given library, it has historically recompiled that entire library, and all libraries that depend on that library. But the compiler has never recompiled any libraries that were deeper in the dependency chain: if you have crates foo and bar, and bar imports foo, and you change the code in bar, foo was not recompiled.
Looking towards the future, I'm most excited about the prospect of using SIMD on stable Rust, which looks to be coming this year: https://github.com/rust-lang/rfcs/pull/2325 https://github.com/rust-lang/rfcs/pull/2325
EDIT: Also worth mentioning is that Rayon (an official Rust library providing easy data parallelism) just reached 1.0 today, which is an important milestone in Rust's march towards ecosystem stability: https://github.com/rayon-rs/rayon https://github.com/rayon-rs/rayon
- yazaddaruvala 9y agoHave there been any thoughts around making the compiler something akin to a stateful server with an embedded datastore for the caching rather than using the filesystem?
- steveklabnik 9y agoNot directly, but there's been some work on changing the compiler's interfaces to ones that would work with that model, in my understanding. It's not out of the realm of possibility.
- Nelkins 9y agoI think this is something that C# and VB.NET do.
- AceJohnny2 9y agoWhat would be the benefit of this approach over using the filesystem?
- azdle 9y agoI'd imagine it would be a benefit where, let's say, every project has `byteorder` in its dependency tree somewhere. If you had a local, stateful, build server that processes every build on your machine, you could re-use the object file from the last time you compiled that library regardless of if it was for this project or not. That's probably not a big gain for just `byteorder`, but if you multiply that by many libs or take into account some of the much bigger ones it could make quite a difference in build time. Even "first" build time for new projects you're building. IIRC, some group in mozilla has already has something working that works like ccache that works (or rewrote ccache to work) with compiling rust. (Which I think is what steveklabnik is alluding to in his neighboring comment.) Although I guess that might only work within a single code base, not sure about that.
- steveklabnik 9y agoYou're thinking of https://github.com/mozilla/sccache https://github.com/mozilla/sccache which is not quite the same thing.
- foota 9y agoMan, I bet that would be blazing fast!
- yazaddaruvala 9y agoAny time you put data onto the file system there is overhead (eg. Memcache, Redis, most databases). Simple things like parsing the bytes into the binary representation go away. You can have more granularity of the cache because you don't need to worry about creating too many files. Not only from a performance perspective but also from a code perspective. More nuanced things like cache locality can be improved with an embedded data store rather than creating files and hoping the OS understands they will always be used together. More advanced things like retaining inverted indexes becomes possible and search performance is dramatically improved.
- zbentley 9y agoThe shortest path to something like that (assuming it's a good idea) would probably not be writing an in-memory incremental compile state server, but storing intermediate artifacts as very cheap-to-serialize files (flatpak or just mmap and a cast), and then storing the files on /dev/shm or some other memory filesystem. That would give you most of the benefits you discussed (unless you clear out the cache/restart the machine) without requiring a huge rewrite of how state is stored. Most of the assumptions I'm making here are unverified, though, so take it with a large grain of salt.
- deleted 9y ago[deleted]
- civility 9y ago> Incremental compilation! Is there some algorithm in Rust which has a necessary big-O? There were compilers in the 90s which ran a million lines per second (on much slower computers). Incremental compilation feels like working around the problem rather than solving it, and I have to imagine the complexity and maintenance is much worse. I'm sure some of the LLVM optimization passes are expensive, but those are used in clang++ too, and it's not terribly slow.
- pcwalton 9y ago> There were compilers in the 90s which ran a million lines per second (on much slower computers). Those compilers performed nowhere near the level of optimization that modern compilers do. > I'm sure some of the LLVM optimization passes are expensive, but those are used in clang++ too, and it's not terribly slow. clang++ is sure slow if it has to rebuild an entire codebase from scratch. The main reason that C++ compilers get away with not having partial compilation is that it forces programmers to do the division into code units manually through separate .h and .cpp files. Rust doesn't have this, except at the crate level, so it needs partial compilation instead. It turns out that partial compilation is better in the first place, because compilation units tend to be fairly coarse-grained: .cpp files frequently grow very large.
- eximius 9y agoIt would recompile foo if you changed something in bar that caused a generic function in foo to monomorphize differently, AFAIK.
- kibwen 9y agoI'm not sure what this is referring to. Generic types don't get monomorphized when exported in libraries, they get compiled to intermediate-language metadata that is then used by downstream consumers to monomorphize as needed. Furthermore I'm pretty sure Rust doesn't allow cyclic dependencies between crates, so if foo somehow depended on bar then bar couldn't depend on foo.