4 ms·
I think a bunch of the "rustc compiles slow" talk comes from the misunderstanding of what rustc does. For example, to do the same things as `rustc` but using C
by oxff 4y ago
I think a bunch of the "rustc compiles slow" talk comes from the misunderstanding of what rustc does.
For example, to do the same things as `rustc` but using C++, you need to run external runtime modifying program to check your program for memory errors .. so that extends your C++ "compile time" by fair amount to even begin to match what rustc does.
- pjmlp 4y agoOr use modern IDEs that run the static analysis in the background already spotting many of those issues before the build takes place.
- jstimpfle 4y agoThe question would be for me, can we run those slow-rustc cases faster by skipping the part corresponding to "external checker program"? Or is that part required for each and every build, even after tiny changes or no changes at all?
- oxff 4y agoWell, you are asking about disabling borrow checker here, one of the main selling points of Rust and rustc here so I think that's out of the question. When you do full comparison of what rustc does, and compare it to what you need to do in C++ project to match it, the compile times aren't actually slow since rustc does more with actual guarantees.
- jstimpfle 4y agoBut that was my point, I don't necessarily want to do more. In general I want results faster, and am not willing to trade build speed for more safety checks unconditionally. Having some additional features and checkers is nice, and can even be a life saver, but having to pay a high cost each time I hit compile is not acceptable.
- PoignardAzur 4y agoTo expand on my other answer, part of the problem is that Rust's compile time complexity is in large part spent on knowing what code to execute, not just whether the code is valid. So the compiler will spend some time inferring the types of different variables and what traits those types implement, which is necessary to know which trait methods get called, etc. Dynamically-typed languages get to skip all this and say "my type is either a number or an object, because everything in the universe is either a number or an object", and methods are selected through dynamic dispatch (usually by storing a ton of function pointers everywhere). Rust can't just do dynamic typing and skip the compile-time logic, though you can get close by using lots of dyn traits.
- PoignardAzur 4y agoRust has a fairly powerful incremental compilation engine, so it tries to avoid re-computing checks if the relevant code hasn't changed. In practice it still recomputes a lot of stuff though. It's not that relevant though, because the longest part of any Rust build is the dependencies, and those are never recompiled. Most projects compile relatively fast once you've built them once.