Release builds are twice as fast compared to debug builds for my project


#1

I am currently at around ~ 18k loc but I split a lot of code into separate crates inside a workspace.
I didn’t really use CARGO_INCRMENTAL because I ran into a few bugs in the past but I recently turned it on again.

My compile times went down from 8 seconds to 4.2 seconds for one specific example that I am currently working on. I also tested release builds and to my surprise they are even faster. It currently builds in 2.56 seconds with --release. I have a 16 thread CPU so this might be related, maybe release builds can make use of more cores?


#2

Perhaps debug builds generate more code? (assertions, bounds checks)


#3

Now use lto = true. :slight_smile:


#4

I don’t think it works with CARGO_INCREMENTAL=1. It crashes with

rustc: /checkout/src/llvm/lib/Transforms/Scalar/GVN.cpp:1933: bool llvm::GVN::replaceOperandsWithConsts(llvm::Instruction*) const: Assertion `!isa<Constant>(Operand) && "Replacing constants with constants is invalid"' failed.

#5

That’s unfortunate. Maybe something for the bug tracker?


#6

I do recall there being mention of release builds becoming faster than debug builds for incremental compilation a while back. Here’s a mention of such behavior. Not sure how much the landscape has changed since that post.

**Edit:** Rereading, I am confused. So you are _not_ using incremental? Then what change are you referring to when you say "my compile times _went down_"? **Edit 2:** Never mind, I see it now:

I split a lot of code into separate crates inside a workspace

Edit 3: ah, okay, the crash was for lto = true. Okay, I think I got the full picture now. :slight_smile:


#7

My compile times went down with incremental builds and decreased even more (by a factor of ~2) when doing a release build.


#8

I also tested it with https://github.com/gfx-rs/

gfx git:(master) CARGO_INCREMENTAL=1 cargo build --example deferred
   Compiling gfx_app v0.6.0 (file:///home/maik/src/gfx)
    Finished dev [unoptimized + debuginfo] target(s) in 4.3 secs

gfx git:(master) CARGO_INCREMENTAL=1 cargo build --example deferred --release
   Compiling gfx_app v0.6.0 (file:///home/maik/src/gfx)
    Finished release [optimized] target(s) in 3.10 secs

Release builds are again faster.

Edit: And without incremental compilation:

gfx git:(master) CARGO_INCREMENTAL=0 cargo build --example deferred
   Compiling gfx_app v0.6.0 (file:///home/maik/src/gfx)
    Finished dev [unoptimized + debuginfo] target(s) in 6.57 secs

gfx git:(master) CARGO_INCREMENTAL=0 cargo build --example deferred --release
   Compiling gfx_app v0.6.0 (file:///home/maik/src/gfx)
    Finished release [optimized] target(s) in 12.2 secs

#9

With my project I noticed that the build time from time to time is very different, even if nothing is changed

    Finished dev [unoptimized + debuginfo] target(s) in 43.99 secs
    Finished dev [unoptimized + debuginfo] target(s) in 28.87 secs
    Finished dev [unoptimized + debuginfo] target(s) in 31.28 secs
    Finished dev [unoptimized + debuginfo] target(s) in 30.5 secs
    Finished dev [unoptimized + debuginfo] target(s) in 28.53 secs

In the release build it is much more stable

    Finished release [optimized] target(s) in 23.22 secs
    Finished release [optimized] target(s) in 21.36 secs
    Finished release [optimized] target(s) in 21.18 secs
    Finished release [optimized] target(s) in 21.20 secs
    Finished release [optimized] target(s) in 21.26 secs
    Finished release [optimized] target(s) in 21.43 secs