2.6 KiB
2.6 KiB
Link Time Optimization (LTO) in OxiCloud
Overview
OxiCloud uses Link Time Optimization (LTO) to significantly improve runtime performance. LTO is a technique that allows the compiler to perform optimizations across module boundaries during the linking phase, which can lead to better inlining, dead code elimination, and overall more efficient binaries.
Implemented Optimizations
This project uses the following optimization settings:
Release Profile
[profile.release]
lto = "fat" # Full cross-module optimization
codegen-units = 1 # Maximum optimization but slower compile time
opt-level = 3 # Maximum optimization level
panic = "abort" # Smaller binary size by removing panic unwinding
strip = true # Removes debug symbols for smaller binary
Development Profile
[profile.dev]
opt-level = 1 # Light optimization for faster build time
debug = true # Keep debug information for development
Benchmark Profile
[profile.bench]
lto = "fat" # Full optimization for benchmarks
codegen-units = 1 # Maximum optimization
opt-level = 3 # Maximum optimization level
Performance Improvements
The optimizations typically result in:
- Smaller binary size: Removing unused code and metadata
- Faster execution: Better inlining and code optimizations
- Reduced memory usage: More efficient code layout and execution
LTO Options Explained
- fat: Also known as "full" LTO, performs optimizations across all crate boundaries. Maximum optimization but longest compile time.
- thin: A faster version of LTO that trades some optimization for compile speed. Good for development.
- off: No cross-module optimization.
Build Time Impact
While LTO provides runtime performance benefits, it increases compilation time. For OxiCloud, we chose:
- Development builds: Minimal LTO (
opt-level = 1) for faster iteration - Release builds: Full LTO for maximum end-user performance
- Benchmark builds: Full LTO to measure actual optimized performance
Measuring the Impact
To measure the impact of these optimizations, run our benchmarks:
# Run benchmarks with all optimizations
cargo bench
# Compare with non-optimized build (remove for comparison only)
RUSTFLAGS="-C lto=off" cargo bench
When to Adjust Settings
Consider adjusting these settings if:
- You need faster compile times during development
- You're experiencing unexpected runtime behavior
- You want to experiment with optimization/binary size tradeoffs
For most users, the default settings should provide a good balance of performance and usability.