Skip to content

Commit

Permalink
change(rust): Use link-time optimisation in release builds (#4184)
Browse files Browse the repository at this point in the history
* Move Rust optimisations to Cargo.toml

Previously they were in the Dockerfile,
so they only applied to those builds.

* Use link-time optimisation in release builds

* Retry after log ssh failures in full sync test

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
teor2345 and mergify[bot] authored Apr 27, 2022
1 parent d164c75 commit 2423f59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ opt-level = 1
[profile.release]
panic = "abort"

# Speed up release builds and sync tests using link-time optimization.
# Some of Zebra's code is CPU-intensive, and needs extra optimizations for peak performance.
#
# TODO:
# - add "-Clinker-plugin-lto" in .cargo/config.toml to speed up release builds
# - add "-Clinker=clang -Clink-arg=-fuse-ld=lld" in .cargo/config.toml
# - also use LTO on C/C++ code:
# - use clang to compile all C/C++ code
# - add "-flto=thin" to all C/C++ code builds
# - see https://doc.rust-lang.org/rustc/linker-plugin-lto.html#cc-code-as-a-dependency-in-rust
lto = "thin"

[patch.crates-io]

# TODO: replace with upstream librustzcash when these changes are merged (#3037)
Expand Down
6 changes: 0 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ RUN if [ "$(uname -m)" != "aarch64" ]; then \
&& \
rm -rf /var/lib/apt/lists/* /tmp/*

# Optimize builds. In particular, regenerate-stateful-test-disks.yml was reaching the
# GitHub Actions time limit (6 hours), so we needed to make it faster.
#
# TODO: apply this optimisation level to all release builds in .cargo/config.toml
ENV RUSTFLAGS "-C opt-level=3"

ENV CARGO_HOME /app/.cargo/
# Build dependencies - this is the caching Docker layer!
RUN cargo chef cook --release --features enable-sentry --recipe-path recipe.json
Expand Down

0 comments on commit 2423f59

Please sign in to comment.