TL;DR increase developer iteration speed (incremental compilation time reduced by 95%+)
What problem are you trying to solve?
It is currently common to use cargo build --release when developing the analyzer because the runtime performance of an optimized build is ~3x faster, making it optimal for testing the analyzer against large repos (it makes the difference between a 3 minute monorepo scan and a 10 minute one).
However, when using --release, when a single line changes, the binaries need to be rebuilt, and that takes over 2 minutes (on a very fast M1 Macbook), significantly reducing the ability to iterate quickly.
The reason for this is that we currently use lto = true for release mode (which is important for actual releases, but not development).
To illustrate, here is a trace of a --release compilation where all crates have been compiled and then 1 single line of code in analyze.rs is changed:
As you can see, 1m56s are spent in the linker, (despite only 1 second of actual codegen).
What is your solution?
Introduce a release-devCargo profile, which is inherited from --release mode, but turns off lto and includes standard functionality from --debug (symbols, assertions, etc.)
This has numerous benefits
We get the same runtime speed as --release (tested on a mono-repo, 96s analysis vs 95s analysis)
We get debug assertions, debug symbols, etc.
We get comparable compile times to --debug.
Effect
Whereas before, an incremental --release build took 2m1s, an incremental release-dev build takes around 2s:
Methodology
Build the datadog-static-analyzer binary completely from scratch.
2. Change a single line of code:
```rust
// crates/static-analysis-kernel/src/analysis/analyze.rs
// ...
let cache_bust = 1; // (number changed to trigger recompilation)
TL;DR increase developer iteration speed (incremental compilation time reduced by 95%+)
What problem are you trying to solve?
It is currently common to use
cargo build --release
when developing the analyzer because the runtime performance of an optimized build is ~3x faster, making it optimal for testing the analyzer against large repos (it makes the difference between a 3 minute monorepo scan and a 10 minute one).However, when using
--release
, when a single line changes, the binaries need to be rebuilt, and that takes over 2 minutes (on a very fast M1 Macbook), significantly reducing the ability to iterate quickly.The reason for this is that we currently use
lto = true
forrelease
mode (which is important for actual releases, but not development).To illustrate, here is a trace of a
--release
compilation where all crates have been compiled and then 1 single line of code inanalyze.rs
is changed:As you can see, 1m56s are spent in the linker, (despite only 1 second of actual codegen).
What is your solution?
Introduce a
release-dev
Cargo profile, which is inherited from--release
mode, but turns offlto
and includes standard functionality from--debug
(symbols, assertions, etc.)This has numerous benefits
--release
(tested on a mono-repo, 96s analysis vs 95s analysis)--debug
.Effect
Whereas before, an incremental
--release
build took 2m1s, an incrementalrelease-dev
build takes around 2s:Methodology
datadog-static-analyzer
binary completely from scratch.❯ cargo build --profile release-dev --bin datadog-static-analyzer Finished
release-dev
profile [optimized + debuginfo] target(s) in 1m 07sAlternatives considered
What the reviewer should know
--release
mode)