Build times and optimizations

After reading I experimented with optimization levels in grin/Cargo.toml like this:

opt-level = 1

and got these compile times for cargo clean; time cargo build
0 (20min) default. But rust functions don’t get zero-overhead here.
1 (45min) enables rust’s zero-overhead
2 (50min) “reasonable” during development even for debug=yes builds
3 (60min) --release default. “crazy optimizations, throw everything just to see what sticks”

Measurements on a MBP (2015, i5) on commit f0cf903adc and on latest master build times are similar.

Going from default (0) to 1 doubles the compile time, but crates can presumably have different opt-levels, possibly also within a workspace where dependencies are shared.

There’s also lto = true (link time optimizations) for inlining external crates. Not recommended during development.

What kind of optimizations are these? Better bytecode?

Is there any kind of documentation?

The opt-level value is forwarded to llvm or whatever compiler is below rustc, so trying man cc gives

 Code Generation Options
       -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4
              Specify the optimization level to use:

The link time optimization is probably forwarded to the linker (I like gold, but probably something less unusual is used by cargo)

rustc by itself just produces some intermediary bytecode-ish stuff. Probably google “rustc IR” for more on that.