I've been experiencing performance issues with my Rust compilation times and I'm looking for some advice on how to optimize it. Here's my current situation:
- The most time-consuming steps in my compilation process are
codegen_crate
(~5s) andlink
(~10s). - The total compilation time is ~20 seconds.
- I've used the
-Z self-profile
option to gather this information.
[profile.dev]
incremental = true
[lib]
path = "src/lib.rs"
crate-type = ["lib", "staticlib", "cdylib"]
[dependencies]
flutter_rust_bridge = { version = "=1.67.0", features = ["uuid"] }
indexmap = "1.7"
thiserror = "1.0"
anyhow = "1.0"
walkdir = "2.3.2"
sled = "0.34.7"
parking_lot = { version = "=0.11.2", features = ["deadlock_detection"] } # Use to detect deadlocks for sled.
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
bincode = { version = "2.0.0-rc.2", features = ["serde"] }
chrono = { version = "0.4", features = ["serde"] }
once_cell = "1.17"
strum_macros = "0.24"
sentry = { version = "0.30", features = ["anyhow"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
sentry-tracing = "0.30"
sentry-backtrace = "0.30"
openssl = { version = "0.10", features = ["vendored"] }
enum_dispatch = "0.3"
crossbeam = "0.8"
heck = "0.4"
itertools = "0.10"
notify = "5.1"
notify-debouncer-mini = "0.2"
blake3 = "1.3"
camino = "1.1"
# Tools
regex = "1.7"
# Analyse
rake = "0.3.3"
lingua = { version = "1.4.0", default-features = false, features = ["english", "french", "italian", "spanish", "dutch"] }
infer = "0.13"
stop-words = "0.7.0"
## Search
milli = { git = "https://github.com/meilisearch/meilisearch.git", rev="9882029", default-features = false }
either = "1.8"
[dependencies.uuid]
version = "1.3"
features = [
"v4", # Lets you generate random UUIDs
"fast-rng", # Use a faster (but still sufficiently random) RNG
"macro-diagnostics", # Enable better diagnostics for compile-time UUIDs
]
[dev-dependencies]
assert_fs = "1.0"
serial_test = "1.0"
include_dir = "0.7"
filetime = "0.2"
[features]
test = []
What are the improvements, in order of the best ways to improve build performance, for now I'm guessing to do:
- Split the project into a sub-crate.
- Change the linker used. Try mold
Related interesting topics about compilation performance:
I'd appreciate any suggestions on how to improve the performance of these steps, or any other general advice for speeding up the compilation process. Thanks in advance for your help!