Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Optimize Rust Build Process and Cargo Settings
This PR introduces several optimizations to improve our Rust build process and cargo settings. These changes aim to reduce build times and enhance runtime performance.
Changes
1. GitHub Actions Workflow (
.github/workflows/docker-publish.yml
)actions-rs/toolchain@v1
.cargo-chef
for efficient dependency caching:cargo-chef
, prepare recipe, and cook dependencies.cargo-chef
artifacts.CARGO_TERM_COLOR
environment variable for colored output in CI logs.These changes will significantly reduce build times by caching dependencies and build artifacts between runs.
2. Cargo Settings (
Cargo.toml
)Added release profile optimizations:
lto = "thin"
: Enables thin Link Time Optimization, which is faster than full LTO but still provides good optimization.codegen-units = 1
: This can improve runtime performance at the cost of longer compile times.opt-level = 3
: Sets the highest level of optimization.panic = "abort"
: Reduces binary size by removing panic unwinding code.These optimizations will improve the runtime performance and reduce the size of our binary.
3. Cargo Configuration (
.cargo/config.toml
)Added a new configuration file to enable parallel compilation:
This setting allows Cargo to use up to 4 parallel jobs during compilation, which can significantly speed up the build process our github actions runner (which uses 4 cores).
Why These Changes?
Faster CI Builds: By implementing caching, using
cargo-chef
, and enabling parallel compilation, we can significantly reduce the time it takes to build our project in CI, especially for incremental changes.Improved Performance: The release profile optimizations in
Cargo.toml
will result in a more efficient binary, potentially improving runtime performance.Smaller Binary Size: The
panic = "abort"
setting can lead to a smaller binary, which can be beneficial for deployment and startup times.Better CI Logs: Setting
CARGO_TERM_COLOR
will make our CI logs more readable with colored output.Optimized Resource Usage: By specifying the number of parallel jobs, we can better control and optimize our resource usage during the build process.
These changes strike a balance between build time optimization and runtime performance, which should lead to a more efficient development and deployment process. The combination of caching strategies, parallel compilation, and binary optimizations should provide noticeable improvements in both build times and runtime performance without requiring changes to our core application code.