Hello, I've been working with rust for about a year, and did few projects that are used daily, mostly tokio based or cli without many dependancies.
I am now working on project that uses axum, reqwest, tokio, sqlx, utoipa (and few utility libs). I understand that rust compilation times are not as fast as C (and similar) but I think I'm missing something - when I change single line in project with total of ~1000 lines it takes almost 2 minutes for change to be cargo-check + compiled.
What steps should I take to speed things up?
cargo build -vvv will tell you why it's rebuilding each dependency (look for the first miss).
Issues I know of:
Mac Docker filesystem in some configurations only supports writing timestamps with whole-second precision, but Cargo expects filesystem to preserve nanosecond precision. This will make Cargo in Docker builds chronically bad at caching.
Rust analyzer may be sharing the build directory, but have different env vars set, which causes sys crates to rebuild.
Try setting env var CARGO_BUILD_BUILD_DIR=/var/tmp/cargo_$RANDOM (needs Rust 1.91). This will cause one full rebuild, but then it will give you a separate cache dir for the project used only where the env var is set, so other tools and IDE won't be invalidating it. And it will be outside network mount in Mac Docker too in case you're using that.
Adding to that, the initial delay is caused by cargo run being blocked on rust-analyzer's cargo check. If you set targetDir in r-a then they won't contend anymore. This will also cause them to have separate build-dirs.
We're looking at having cargo check only grab a lock for build-dir so that setting only that is sufficient. Someone is also actively exploring how to change our locking scheme to reduce contention.