tobogganSe connecter

louise

The Louise language: compiler, runtime, std, tooling

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

56 lignes · 4304 octetsBrut · Historique

ADR 0042: Smaller release binaries

Status: Proposed (2026-10-13); needs engineering review (#44), in particular the use of RUSTC_BOOTSTRAP=1 for the runtime archives' standard library.

Context

A release hello world was 817 KB, and the HTTP demo 1.2 MB. What was in hello (2026-10-13):

  • Symbol table and strings: about 170 KB. Release builds stripped debug information (issue #115) but kept the symbols.
  • Backtrace symbolisation: 176 KB of the code. This is std's DWARF reader and demangler (gimli, addr2line, miniz_oxide, rustc_demangle), linked because the default panic hook can print a backtrace. The runtime is panic = "abort", and its panics are bugs; the backtrace is the least useful part of their report.
  • The rest: std's other code (about 100 KB), the runtime (about 100 KB), mimalloc (about 95 KB), and the program.

For comparison, a stripped Rust hello world is 350 KB and GHC's 980 KB.

Decision

  1. Strip the symbol table of release executables (-Wl,--strip-all instead of --strip-debug), unless the C flags ask for debug information (LOUISE_CFLAGS=-g, which keeps both, for debugging or profiling a release build).
  2. Fold identical functions (-Wl,--icf=safe) when linking with lld (ThinLTO links always do). safe keeps apart functions whose address is taken.
  3. Rebuild std without its backtrace feature for the fast and lto runtime archives (scripts/runtime.sh): -Zbuild-std=std,panic_abort -Zbuild-std-features=. Panic messages stay; the backtrace goes.
    • The same stable compiler (rust-toolchain.toml, which now lists rust-src) builds it, with RUSTC_BOOTSTRAP=1 since -Zbuild-std is unstable.
    • So the lto archive's LLVM stays the stable rustc's, which the system's lld can read (ADR 0032).
    • Without rust-src, or with LOUISE_SMALL_STD=0, the archives use the prebuilt std as before.
    • The checked runtime (tests, debug builds) is unchanged.

Measurements

Release builds on x86-64, clang and lld 22, best of 9 interleaved runs, one thread, main (8d6cde2) against this change.

beforeafter
hello816,840 B395,448 B−52%
examples/http_demo1,201,104 B745,320 B−38%
a benchmark (html)905,440 B485,944 B−46%

Steps on hello:

  • strip: 647 KB;
  • folding: 638 KB;
  • the std without backtraces: 395 KB.

Speed is unchanged. Every tests/bench program is within ±4% in wall clock, and html, floats, lists and dict within ±1.2% in cycles against the same runtime variant.

Rejected on the way:

  • A pinned nightly (the TSan toolchain) to rebuild std. Its LLVM is newer than the system lld, which then can't read the lto archive; release builds fell back to fast and lost the cross-language LTO: floats +43% and html +27% in cycles.
  • Dropping unwind tables: nothing measurable (they are std's, prebuilt).

Consequences

  • Diagnosis: a Rust panic inside the runtime of a release program prints its message and location, without a backtrace. Release executables have no symbols, so perf and debuggers need a build with LOUISE_CFLAGS=-g. Tests that read symbols (unused_runtime_functions_are_left_out, program_functions_never_keep_the_thread_pointer) build that way.
  • Toolchain:
    • RUSTC_BOOTSTRAP=1 lets a stable compiler accept unstable flags. Distributions build Rust this way, but Rust doesn't promise it.
    • A rustc update can change the build-std flags.
    • It is confined to scripts/runtime.sh, with a fallback.
  • Build time: scripts/runtime.sh compiles std twice more (fast and lto), about a minute on a cold cache.
  • Rust native dependencies (kind = "cargo", ADR 0031) still bring their own std, linked as before. native_dependencies_of_every_kind passes.

Alternatives considered

  • panic_immediate_abort: smaller still, but a runtime bug would abort without a word.
  • A nightly toolchain: see above. It works only where the system's lld is as new as the nightly's LLVM.
  • Linking with the nightly's own rust-lld: ties every program build to that rustup toolchain.
  • -Os for the runtime: slower hot paths for little gain once the backtrace code is gone.
  • Nothing: binaries twice the size of a stripped Rust program's.