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.

58 lignes · 4046 octetsBrut · Historique

ADR 0030: Release builds stay in one C unit (ThinLTO rejected for now)

Status: Proposed (2026-10-12, issue #118); needs engineering review (#44).

Context

  • Release builds are one C unit, because the C compiler can't inline across units (issue #61). Debug builds of large programs are split per module (ADR 0029), but a cold release build stays dominated by clang -O2 on one large unit: about 1.1 s for http_demo.
  • ThinLTO (-flto=thin, linked by lld) restores inlining across units at link time. That would let release builds be split and compiled in parallel too.
  • The owner's bar for shipping it: no benchmark runs more than 2% more instructions than with one unit.

Measurements

The setup:

  • Versions: clang 22.1.8, lld 22.1.8.
  • Programs: every program of tests/bench, release.
  • Metric: user-space instructions on one scheduler thread (exact to a few parts in 10⁸).
  • Forced splitting: these programs are under the 64 KB split threshold, so LOUISE_MIN_UNIT_BYTES=0 split them per module (about 3 units each).
BenchmarkSplit, plain -O2Split, ThinLTO
arith+2.6%+2.6%
arrays−0.4%0.0%
dict+1.0%+0.8%
effects+1.1%0.0%
fanin+1.5%+1.3%
floats+1.1%+1.1%
html+1.6%−1.0%
idle+0.2%−0.1%
lists+0.5%−0.4%
messages+0.3%−0.4%
parallel0.0%0.0%
selective+0.2%−0.1%
timers0.0%−0.4%
  • arith stays at +2.6%. Adding -O2 at link time, or raising ThinLTO's import limit (-import-instr-limit=1000), changed nothing.
  • The likely cause is the calling convention, not inlining. Every function takes six register arguments (docs/runtime-abi.md). In one unit they are static, so the C compiler drops the arguments a function doesn't use. Across units they are external, and ThinLTO doesn't change their signatures. arith's fib(30) is mostly calls.
  • What it would have saved: a cold release build of http_demo takes 1130 ms in one unit, and 570 ms split per module with ThinLTO (−50%, best of 3).

Decision

Release builds stay in one unit; ThinLTO is not used. arith misses the bar.

LOUISE_MIN_UNIT_BYTES stays, as a diagnostic: it lowers the threshold for splitting a program, so the measurement above can be repeated. To compare the three builds:

LOUISE_C_UNITS=1                                    # one unit
LOUISE_C_UNITS=8 LOUISE_MIN_UNIT_BYTES=0            # split, plain -O2
LOUISE_C_UNITS=8 LOUISE_MIN_UNIT_BYTES=0 \
  LOUISE_CFLAGS=-flto=thin LOUISE_LD=lld            # split, ThinLTO

Consequences

  • Release builds of large programs keep their cold compile time (about 1.1 s for http_demo). Warm release builds are not affected: they reuse their object, or are skipped (ADR 0025 Revision 1).
  • Ways to revisit, each needing its own measurement against the same bar:
    • Internal linkage under LTO: emit functions static within a unit, with external wrappers only for those called from other units, so the signatures can change again. This is a code-generation change.
    • Cross-language LTO with the runtime (#127). It changes how the runtime ships and needs its own ADR. It would also give the runtime's hot paths to the inliner.
    • A newer LLVM whose ThinLTO does dead-argument elimination across modules.
  • Plain split units are not used for release either: they cost up to 2.6% with no link-time recovery.

Alternatives considered

  • ThinLTO for release, accepting arith's +2.6%. It halves cold release builds. The owner set the bar at 2% before the measurement, and arith (numeric code through traits, mostly calls) is the kind of code the language specialises for (ADR 0013).
  • ThinLTO only for programs above the split threshold. The benchmarks are small, so the measurement here would say nothing about the programs it would apply to. Measuring them would mean a separate suite of large programs.