Files
Oxicloud/LTO-OPTIMIZATIONS.md
T
2025-03-26 18:33:22 +01:00

78 lines
2.6 KiB
Markdown

# 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
```toml
[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
```toml
[profile.dev]
opt-level = 1 # Light optimization for faster build time
debug = true # Keep debug information for development
```
### Benchmark Profile
```toml
[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:
1. **Smaller binary size**: Removing unused code and metadata
2. **Faster execution**: Better inlining and code optimizations
3. **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:
```bash
# 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:
1. You need faster compile times during development
2. You're experiencing unexpected runtime behavior
3. You want to experiment with optimization/binary size tradeoffs
For most users, the default settings should provide a good balance of performance and usability.