I cant understand what last single build takes over 4 minutes

I have a project which takes over 5 minutes to compile after every time I change a single letter. I am attaching the timings output below

Can you provide some more detail? It's not even clear what crate you're changing, let alone if it's a full build, incremental, check-only, etc.

its my own code and both debug and release build behave the same even cargo check takes like a minute

a clean build takes well over 40 minutes

That's still not a lot of info — what crate? game-system? What is the "single character" you're referring to, part of a string? A hot function?

Without any further details all I can say is try splitting the binary up into multiple crates, which would allow them to be compiled in parallel and reduce the incremental timing.

1 Like

what do you mean what crate? @jhpratt I told you It is my own code it is not public I did split it into multiple crates and a single character change means literally a single character such as removing a space from a source file is enough to get 4+ minutes despite no real source code being changed

Crate doesn't necessarily mean it's public. Without any code or further details, what I've said is the extent of help I or anyone else will be able to give you. All you've said is that you make some seemingly random change and that it takes four minutes to compile — there's nothing to go off of there.

The timings show that a bunch of your dependencies are getting compiled, which shouldn't happen when you've only changed your own code. This could mean that something happened in between the previous build and the new one that changed timestamps on disk, or deleted some of the previously compiled artifacts, or recompiled things with different compiler options.

Do you have anything running on your system that might be automatically rebuilding your project or otherwise touching it? Maybe an IDE that is using different build settings than the command-line tools?

Can you reproduce the problem on a different computer or a different user account?

If this doesn't help, try building with CARGO_LOG=debug in your environment; this will print out a bunch of information about what sources Cargo thinks have changed.

4 Likes

I am using vim with rust-analyzer and I recently reinstalled my os so everything is new with no other user accounts what I noticed is that nearly all the time is taken by the game-system bin everything else including game-system lib builds relatively fast

For your builds, try changing CARGO_TARGET_DIR to a non-standard location, which isn't shared with your IDE or other tools or any other project.

Something causes vendored openssl to be recompiled. Some tool is messing with the target dir.

It might be related to resolver = "2" feature. If some tool doesn't understand it, it will resolve features differently, which will need rebuilding dependencies with different features enabled.

I checked that first vendored openssl takes only around 20 secs and it does not recompile I am removing modules one by one to understand flamegraph shows that all this time is caused by monomorphization and codegen

I closed my ide also I turned all the optimizations for the debug build I reduced the rebuild time to around 18 seconds but for some reason for every consecutive cargo build it rebuilds the package all together so every cargo build takes 18 seconds even if theres no change whatsoever

Possibly there's some weird antivirus keep touching things.

I dont have an antivirus actually I just reinstalled my previously bloated arch instance so I literally have like 20 background services running no more

I noticed on the flamegraph that despite the fact that I set lto = "off" under [profile.dev] it still keep happening and take a good chunk of time

this seems to be a weirdness of calling nightly cargo rustc because cargo build behaved as expected and did not rebuild

issue seems to be because of warp. Seems it is not suitable for routes more than 3-4 this is a confirmed case as far as I understand from their bug reports on github

I've been using warp lately and would be interested in where you found that warp is not suitable for more than 3-4 routes. Could you post a link to a where you found this information? I'd be interested reading more about it.

I wasn't able to find any issues related to this on GitHub - seanmonstar/warp: A super-easy, composable, web server framework for warp speeds..

Thanks in advance!

Compile time is in minutes... · Issue #507 · seanmonstar/warp · GitHub here you can read the discussion if you have lots of endpoints like me compile time takes forever

Use the macro as written here: