3 ms·
Stats like this remind me how insanely slow the rust compiler is. Its possible to write a compiler which spends 110 cycles per source byte. How many cycles per
by josephg 6y ago
Stats like this remind me how insanely slow the rust compiler is. Its possible to write a compiler which spends 110 cycles per source byte. How many cycles per source byte does the rust compiler consume? It seems like its 4-5 orders of magnitude slower - which is so crazy!
Why is it so hard to optimize? Are we just being lazy? Whats going on?
- coldtea 6y ago>Are we just being lazy? "We" being who here? I'm pretty sure the Rust devs work like crazy on the language and its features -- they're not being "lazy". At best, they deprioritize compiler speed work, which is not the same as laziness.
- manfredo 6y agoPerhaps a better question is, what are compiler authors optimizing for? A compiler that runs in 3 seconds that produces code that's half the speed as a compiler that runs in 3 minutes is a worse option than the latter in plenty of use cases. And if we really care about minimizing compile times (and if we're being a little pedantic) we can just use an interpreted language and achieve zero compile times, by virtue of not doing any compiling at all. Rust and Pascal have different use cases in mind. I think a better question would be what are the different design philosophies between the two languages, and how this impacts compiler implementations.
- samatman 6y agoThere is an amount of time spent compiling which has a qualitative effect on my programming. I start to feel it around ten seconds, definitely by thirty; three minutes is way over the line. I start to be reluctant to make small tweaks. I want to program in 'blocks', time compiling with bathroom breaks. My frame is just wrecked, and I'm fairly convinced that code quality suffers from this. I like what Zig is doing, by taking such care to keep unoptimized builds as fast as possible. Release builds can run overnight for all I care, I'm fine with taking arbitrary amounts of time to get the fastest end product I can have. But I firmly believe that a language which can't give me a build in a handful of seconds is missing out, and it's a real pity Rust is in that category. It's possible that a language with type inference and a borrow checker simply must have slow compile times, that it's inherent. I doubt that somehow, though I concede that one-pass compiling a la Turbo Pascal is likely impossible.
- darksaints 6y agoAre those your compile times with incremental compilation?
- samatman 6y agoThose are real compile times I've experienced, the post is about what it feels like for compiling to take "too long" and approximately what "too long" is. Rather than what it's like to use a particular compiler on a specific project, at this moment in time.
- 082349872349872 6y agoPascal's original role was as a teaching language. Students will invariably compile multiple times making many errors along the way, but never run their final iteration in production. For those who don't remember "funny money" I'll point out that, not only did we wear onions on our belts, but CPU usage was charged back in the day. :beratna owte wameku ere nebula:
- chungy 6y ago> not only did we wear onions on our belts It was the style at the time.
- saagarjha 6y agoWell, ideally you have both! For what I’m working on right now, a plain debug compile takes an hour. Since I usually interact with a debug build for just a few minutes (if I’m not playing tricks) I would really like a “make this faster to compile but slower to run” option. (I doubt one could exist, but you never know.)
- pjmlp 6y agoExcept you are forgetting that with many native compilers, I can choose to wait 3 seconds or 3 minutes, I am not stuck with a frozen compile time, because their toolchains allow me to choose how long I am willing to wait, including the option to use binary libraries on their package managers. D, C++, Ada, Eiffel, Delphi,...
- mhh__ 6y agoPerforming semantic analysis on a language like Rust is much harder than Pascal i.e. to compile a rust file you have to perform static analysis as part of the compilation. It can be faster though. D is a very big language and I can compile the entire compiler in a second flat on my machine (i.e. it's cheap enough not to cache the resulting object file to include in my project)
- zozbot234 6y agoStatic analysis is a minor part of Rust compile cost. The main cost is from optimization, as well as from redundant work caused by monomorphized generic code or custom macros.
- josephg 6y agoThe rust compiler is pretty slow even in debug mode, with optimizations turned off. (Although macros and monomorphization still happen in debug mode). In general I don't buy the complexity argument. Rust is more complex than Go, D or Delphi. But its not 50x more complex, or whatever we would guess from the compilation speed difference. I suspect a lot of the compilation time bloat is a result of all the intermediate representations the code goes through, in order to play nice with LLVM's optimizers and codegen. (Or to put it another way, I suspect a compiler optimized for development mode iteration has the potential to be way faster than rustc.) If you mostly don't care about runtime performance, a debugging compiler could probably also skip monomorphization and just compile everything once and use dynamic dispatch for generics.
- mhh__ 6y agoRust doesn't have to be much slower but when your compiler has three IRs to go through it doesn't help. D is a pretty complex language, but it's explicitly designed around compile times in many locations. Changing the basic implementation of language features probably won't help a huge amount, you could probably get a lot back with a simple backend that does no optimisations other than register allocation. (The main D compiler can do more than this but it lags behind LLVM by quite a way so it's not useful for fast code)
- jml7c5 6y agoThis long series of blog posts ("How to speed up the Rust compiler") will be of interest: https://blog.mozilla.org/nnethercote/2020/09/08/how-to-speed-up-the-rust-compiler-one-last-time/ https://blog.mozilla.org/nnethercote/2020/09/08/how-to-speed... I think they've all been discussed on HN at some point.
- higerordermap 6y agoLLVM. The race between most used compilers is in producing fastest code. There are only few folk who care about correctness and compile times. LLVM, while its drawbacks are not highlighted, is a monolith and only slightly better than GCC in some areas. Compile times being one of them. Not to forget "fast" compilers don't apply many optimizations. There are some rust specific reasons too, like lack of binary dependencies.