Incremental compilation times on Windows 10, Windows 11 and Linux

I have a Rust project (a web server) with these lines of code (measured with loc):

--------------------------------------------------------------------------------
 Language             Files        Lines        Blank      Comment         Code
--------------------------------------------------------------------------------
 Rust                   488       125602        16087        11354        98161
  1. I tried Windows 10:

    and the incremental compilation (changing a file in one deeply nested mod during the cargo-watch -x run) time is:

    15 seconds

  2. I tried Windows 11:

    and the incremental compilation (changing a file in one deeply nested mod during the cargo-watch -x run) time is:

    15 seconds

  3. I tried Ubuntu 24.04:

    and the incremental compilation (changing a file in one deeply nested mod during the cargo-watch -x run) time is:

    11 seconds

Now these are the times if I change a file using a text editor.

If I instead use VSCode with this settings.json file:

{
  "editor.formatOnSave": true,
  "rust-analyzer.checkOnSave": true,
  "rust-analyzer.runnables.extraEnv": {
    "RUST_BACKTRACE": "0"
  },
  "rust-analyzer.cargo.extraArgs": ["--target-dir", "target/rls/"],
  "rust-analyzer.check.command": "clippy"
}

the time for the incremental compilation is much higher:

  • when I save the file rust analyzer starts loading

  • in the bottom bar I can read "cargo clippy" with a loader

  • the cargo-watch in terminal doesn't start immediately

  • after a few seconds it starts and completes the "run" in 19 seconds:

[Running 'cargo run']
   Compiling crate4 v0.1.0 (C:\project\src\crate4)
   Compiling crate3 v0.1.0 (C:\project\src\crate3)
   Compiling crate2 v0.1.0 (C:\project\src\crate2)
   Compiling crate1 v0.1.0 (C:\project\src\crate1)
    Finished `dev` profile [unoptimized] target(s) in 19.14s
     Running `target\debug\app.exe`

Considerations

  • If I use the default Rust compiler times go up from 19 seconds to 30 seconds or more and everything else is the same

  • Between Windows 10 & Windows 11 (same versions of Rust and VSCode and everything else and exactly the same hardware) nothing changes. I think the new Dev Drive is useful to disable the Defender app (which on certain work PCs we do not install by default) but the new ReFS does not bring any time advantages

  • Incremental compilation on Ubuntu is faster but not as much as I hoped

  • I need clippy during development because sometimes it's very useful suggesting things

  • I'm currently using this Cargo.toml:

[profile.dev]
debug = 0

[profile.dev.build-override]
opt-level = 3

Questions

  • Is there a way to start the cargo-clippy in VSCode AFTER the cargo-watch command?

  • How can I change the code so I can avoid all this waiting time between small changes?

What do you think?

1 Like