Enable Link-Time Optimization (LTO) and codegen-units = 1 for Release builds

Aperta Adatta ai principianti
#208 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 5 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
72/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
rust
Ambito
build-system

Direzione di ricerca

La modifica riguarda il Cargo.toml nella radice, sotto la tabella [profile.release] (aggiungila se manca). Imposta lì codegen-units = 1 e lto = true, e lascia invariato il profilo dev. Esegui cargo build --release per verificare che la build vada a buon fine e confronta la dimensione del binario con la baseline; la issue riporta 10,7 MiB prima e 7,6 MiB dopo. Controlla i workflow CI esistenti, perché useranno automaticamente il nuovo profilo, e tieni presente che le build di release diventeranno più lente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hi!

I noticed that in the Cargo.toml file Link-Time Optimization (LTO) for the project is not enabled. I suggest switching it on since it will reduce the binary size (always a good thing to have) and will likely improve CPU performance a bit due to more aggressive compiler optimizations. Additionally, codegen-units = 1 (CU1) option can help too in a similar to LTO way, so I recommend to enable it as well.

I recommend enabling LTO only for Release builds so developers experience won't be affected by the increased build time. Actually, I can propose to use flags directly from this ripgrep profile (like stripping and other things).

Basically, it can be enabled with the following lines to the root Cargo.toml file:

[profile.release]
codegen-units = 1
lto = true # FatLTO - the most aggressive LTO version
<possible other options like strip = true>

I have made quick tests (Macbook M1 Pro, macOS Tahoe 24.1, Rust 1.95, cargo build -r build command, without stripping) - here are the results:

  • Current Release profile: 10.7 Mib, clean build time: 46s
  • Release + FatLTO + CU1: 7.6 Mib, clean build time: 1m 32s

Build time increase shouldn't be a problem since we enable it only for the Release profile - in this case, we would not affect the development lifecycle. If the proposed settings are added to the Cargo.toml file, all binaries (including GitHub Actions-built and released binaries) will be built with the new options automatically.

Thank you.

Lingua principale
Rust
Stelle
247
Fork
30
Merge medio
4g 19h
PR unite (30g)
44

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di symposium-dev/symposium

Tutte le issue di symposium-dev/symposium

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.