
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1197 · main · 10 min 35 s
1Étoiles
0Forks
0Issues
| 1 | #!/usr/bin/env bash |
| 2 | # PGO for the fast runtime archive (issue #193, step 2): builds |
| 3 | # liblouise_rt instrumented, trains it on the benchmarks, rebuilds with |
| 4 | # the profile, and leaves a directory with the result as |
| 5 | # liblouise_rt-fast.a. Link it with: |
| 6 | # |
| 7 | # LOUISE_LIB_DIR=target/pgo/use LOUISE_RUNTIME=fast louise build --release … |
| 8 | # |
| 9 | # The recipe's traps, found the hard way: |
| 10 | # - the *link* needs the driver's `-fprofile-generate` flag, not just the |
| 11 | # archive: without it the profile writer is never registered and no |
| 12 | # .profraw is written (any linker, with or without --gc-sections); |
| 13 | # - the instrumented archive must also be on the link line (it is, as the |
| 14 | # fast archive); |
| 15 | # - PGO applies to the `fast` (machine-code) archive; with ThinLTO the |
| 16 | # runtime is re-laid-out at the program's link, where this profile does |
| 17 | # not reach. |
| 18 | # |
| 19 | # Measured 2026-10-15 (best of 5-8, pinned, interleaved; instructions in |
| 20 | # parentheses): fanin -25% (-22%), selective -17% (-18%), records -8% |
| 21 | # (-11%), html ~+2% (careful re-measure; a first pass said +14%, which |
| 22 | # was run-order noise), the compute benchmarks ~0%. Trained on |
| 23 | # tests/bench. |
| 24 | set -euo pipefail |
| 25 | cd "$(dirname "$0")/.." |
| 26 | |
| 27 | out=target/pgo |
| 28 | raw="$PWD/$out/profraw" |
| 29 | rm -rf "$out" |
| 30 | mkdir -p "$raw" "$out/bin" "$out/use" |
| 31 | |
| 32 | echo "== instrumented runtime" >&2 |
| 33 | RUSTFLAGS="-Cprofile-generate=$raw" \ |
| 34 | cargo build --quiet --profile runtime -p louise_rt --no-default-features --features mimalloc,tls,crypto \ |
| 35 | --target-dir "$out/gen" |
| 36 | cp "$out/gen/runtime/liblouise_rt.a" "$out/use/liblouise_rt-fast.a" |
| 37 | |
| 38 | echo "== instrumented benchmarks" >&2 |
| 39 | # The link needs the driver's flag (see the header); the training builds' |
| 40 | # own C is instrumented too, harmlessly. |
| 41 | for program in tests/bench/*.lse; do |
| 42 | name="$(basename "$program" .lse)" |
| 43 | LOUISE_LIB_DIR="$PWD/$out/use" LOUISE_RUNTIME=fast \ |
| 44 | LOUISE_CFLAGS="-fprofile-generate=$raw" \ |
| 45 | ./target/dist/louise build --release "$program" -o "$out/bin/$name" >/dev/null |
| 46 | done |
| 47 | |
| 48 | echo "== training run" >&2 |
| 49 | for bin in "$out"/bin/*; do |
| 50 | [ -f "$bin" ] && [ -x "$bin" ] || continue |
| 51 | "$bin" >/dev/null |
| 52 | done |
| 53 | [ -z "$(ls -A "$raw" 2>/dev/null)" ] && { echo "pgo-runtime: no profiles written (see the header's traps)" >&2; exit 1; } |
| 54 | llvm-profdata merge -o "$out/rt.profdata" "$raw"/*.profraw |
| 55 | |
| 56 | echo "== runtime with the profile" >&2 |
| 57 | RUSTFLAGS="-Cprofile-use=$PWD/$out/rt.profdata" \ |
| 58 | cargo build --quiet --profile runtime -p louise_rt --no-default-features --features mimalloc,tls,crypto \ |
| 59 | --target-dir "$out/final" |
| 60 | cp "$out/final/runtime/liblouise_rt.a" "$out/use/liblouise_rt-fast.a" |
| 61 | echo "pgo-runtime: $out/use/liblouise_rt-fast.a" >&2 |