9 ms·
This is one of the things that really makes me hesitate with Rust. I have a pretty small database project which sometimes needs to slowly stream updates to a w
by josephg 6y ago
This is one of the things that really makes me hesitate with Rust.
I have a pretty small database project which sometimes needs to slowly stream updates to a web browser. Pulling in actix and actix-web added over 1s to my debug mode build time on a fancy new zen3 computer. The web front end isn’t the core of this project - which makes the slowdown really sting. I’m tempted move all the web / actix stuff behind a compilation flag just to keep my coding flow while working on the rest of the project.
I know compilation time is being worked on, but it’s still way slower than it could be. I’d love to see an incremental linker for rust some day that’s able to just replace the methods in the binary which were actually changed between builds.
- IshKebab 6y agoI agree. Hopefully when the Cranelift backend works it will get a lot faster, but even `cargo check` can be pretty slow, and I'm not sure if there is any way around it. One idea I had: can crates.io generate machine independent Rust IR for all of the crates and have cargo download it? Then at least you don't need to parse/check/compile the source code of dependencies for clean builds. Probably wouldn't work for any crates that use `build.rs` or conditional compilation anywhere though (which is probably most of them).
- hobofan 6y agoApart from the conditional compilation problems, you would also have to pre-compile for all different Rust versions. Given the size of a typical `target` directory the artifacts for just a single Rust version will also probably be ~10x as big as the current crate source.
- IshKebab 6y agoMmm good point. An ideal solution for CI would be something like sccache, but I think to get that to work reliably you need to consider it from the beginning (like Bazel did) and Rust just didn't. `build.rs` can do literally anything. Proc macros can do anything. Even a simple `include_str!()` can break distributed compilation. It would be great if Cargo had a "hermetic" mode where you couldn't use `build.rs` and proc macros couldn't do any IO, etc.
- onei 6y agoIt's an interesting idea, and one python has sort of used for a while with wheels (pre-compiled binary packages for specific architecture/OS combinations). For Rust, they could potentially cache the MIR or even a higher level LLVM IR, but perhaps those formats are too unstable or end up extremely complicated.
- volta83 6y agoas long as you are not switching compilers during development, those formats are stable..
- potatochup 6y agoIs it mostly compilation time, or link time? At least for debug builds, I found swapping out the linker to work wonders. There are some examples on https://endler.dev/2020/rust-compile-times/ https://endler.dev/2020/rust-compile-times/ (no affiliation, just 1st google result)
- GrayShade 6y agoDisabling debug information also helps, regardless of the linker.
- volta83 6y agoEnabling opt-level=1 also does wonders. It enables dead code elimination, and removes a lot of code very early.
- josephg 6y agoAwesome thanks for the tips everyone! I wasn’t expecting that. The slowdown is almost all linking time. I’ll try swapping out the linker and playing with build settings.
- KingOfCoders 6y agoCurrently use Rust, was anxious about build times but incremental builds on my machine done with 'watch' are no concern. Switched to a faster linker though. Also 'rust check' is what I most often need which is fast for me. But perceptions are subjective. Using Scala for a long time, Rust compile times are a relief. Not as fast as Go and not as fast as Typescript (which I used with live compiling and Wallaby, Rust is quite away from TS unit testing turn around).
- vbsteven 6y agoI know actix uses lots of generics and macros to match up your functions with varying signatures to Handlers for a request. That might be a reason why it’s slow but I don’t know enough about Rust compilation to be sure. Can’t you put the web stuff in another crate that depends on the main library crate? That way you can build and test your library without all the actix/web stuff.
- Karrot_Kream 6y agoJust use warp. Warp is a lot faster to compile but is also less performant. If web isn't a core part, it's not worth the incremental speedup.
- josephg 6y agoOk I'll take a look at Warp if I can't get my compile times down with the suggestions from others. I initially wrote my code using Tide, but I'm streaming data through long-lived HTTP responses (with a protocol similar to SSR). Tide made this extremely difficult to pull off. Actix (not actix-web) makes this much cleaner, because I can create an actor per web client. The actor owns the connection, and I can send messages to the actor to be translated into bytes and sent over the wire. Even if I use something other than actix-web, I might keep using actix for the actor based programming model (which is a good fit for my project). And if I'm doing that, actix-web seems like the obvious choice for the web component.
- Ygg2 6y agoI have a 5900x and an SSD. For example project like fluent-rs takes about 300-700ms to compile? So I don't know what kind of projects are you running when you hesitate to use Rust?
- brabel 6y agoI have a small project that has around 2k lines now, and it takes over 5 seconds to re-compile. Fast compilers can do 2k lines in less than a second. waiting over 5 seconds for unit tests to run can actually be a problem as it slows down your cycle.
- Ygg2 6y agoSure but fluent-rs is not a small project. I don't have exact numbers but definitely above 2k lines. Even if you exclude the comments. What I mean by it, maybe it's not the line count, but using too much macros and/or monomorphization.