Repository navigation
Count the compiler's instructions with cachegrind in the benchmarks - #9254
Conversation
Changelog🏠 Internal
Semantic Diff1 commit · Full page ✏️ Count the compiler's instructions with cachegrind in the benchmarksf99df21 · cknitt + Claude · Nov 07, 2026, 09:16 UTC · edited Allocation misses slowdowns that don't allocate, such as a scan of a list that already exists. The benchmark job now runs on x64 and also counts, with cachegrind, the instructions the compiler executes on the stress inputs, the parse and format runs and the 15 largest runtime and Belt files; the comment shows both counts in a section each. Base and head are built and measured from the same path, and the runs under cachegrind use a minor heap larger than any benchmark allocates, so two builds of the same compiler give the same counts. Four more stress inputs cover constructs whose compile time and allocations grow faster than their size, and the script, its data and the comment are named after the compiler. |
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
b87cd33 to
f50f384
Compare
e93258a to
8fe5c0c
Compare
✅ Compiler benchmarksAllocated wordsIn total: 456,989,425 → 456,989,425 (±0.00%). None of the 257 benchmarks changed by 0.1% or more. InstructionsIn total: 10,226,962,259 → 10,226,962,259 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Pull request f99df21 compared with base cfdde42 in this run. |
Allocation misses slowdowns that don't allocate, such as a scan of a list that already exists. The benchmark job now runs on x64 and also counts, with cachegrind, the instructions the compiler executes on the stress inputs, the parse and format runs and the 15 largest runtime and Belt files; the comment shows both counts in a section each. Base and head are built and measured from the same path, and the runs under cachegrind use a minor heap larger than any benchmark allocates, so two builds of the same compiler give the same counts. Four more stress inputs cover constructs whose compile time and allocations grow faster than their size, and the script, its data and the comment are named after the compiler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kbf3gG86E3DicyC4NfsFGP Signed-off-by: Christoph Knittel <ck@cca.io>
e4793f2 to
f99df21
Compare
Stacked on #9253. Adds instruction counts next to the allocated words, to catch slowdowns that don't allocate, such as a scan of a list that already exists, and makes both counts exact: two builds of the same compiler give identical numbers.
How it works
Runner: the
benchmarksjob (renamed fromalloc-benchmarks) runs onubuntu-26.04(x64), sincebsccrashes under valgrind on arm64. It uses the OPAM environment and dune cache of the first linux-x64 build job.What runs under cachegrind: after installing valgrind, the job measures with
--instructions. A subset runs undervalgrind --tool=cachegrind --cache-sim=no, and the instructions are read from cachegrind'sI refsline:OCAMLRUNPARAM=v=0x400still reports the allocated words under valgrind, so these runs give both counts. The other runtime and Belt files run natively, for allocated words only.Why the numbers are exact
Two things made the counts of the same compiler differ between base and head:
The garbage collector. The checkouts' paths change the allocated words by a few. That moves the points where the collector runs, and how much of a major cycle is done before the program exits. On the first CI run that changed
stress/InlineChain.resby −2.95% of its instructions, with 17 more words allocated. So the runs under cachegrind useOCAMLRUNPARAM=v=0x400,d=1,s=64M:InlineChain: 151M instead of 228M);d=1, because OCaml reserves a minor heap's worth of address space per possible domain (128 by default), more than valgrind can give.The cost of collecting stays in the allocated words, which these settings don't change.
The paths. The runtime and Belt files are compiled in place with absolute paths in their arguments, which changed their instructions by up to 0.18% (
JsxDOM.res), and every allocation count by a few words. So base and head are built (runtime and Belt) and measured one after the other from the same path,/bench(sudo mount --bind). The stress inputs and data files always go to the same temporary directory.Repeated runs of the same binary differ by at most 0.003% (a temporary experiment step measured base and head twice each). With both fixes, the last CI run gave identical totals on both sides: 456,989,400 allocated words and 10,227,032,665 instructions.
More stress inputs
Four generated inputs join the six from #9253, for constructs whose compile time and allocations grow faster than the size of the input. The growth figures are from local runs, doubling the input:
stress/ObjectFields.res: a 400-field object, every field readstress/TypeAliasChain.res: 60 parameterized aliases, each on the previous onestress/RefsInLoop.res: 300 refs updated in one loopstress/NestedClosures.res: 100 nested closures, each using all outer variablesEach stays below the minor heap of the runs under cachegrind, so the collector doesn't run there either.
The comment
The title is now "Compiler benchmarks", with one section per count. Each section has:
The title's symbol shows the worse of the two sections; otherwise only regression and improvement headlines have one. The instructions section is left out when neither measurement has instruction counts.
When a step fails before the comparison, the comment says "The benchmarks couldn't run for pull request …" with a link to the run, instead of keeping the report of an earlier commit.
Names
The benchmarks count more than allocations now, so they're named after the compiler:
scripts/compilerBenchmarks.jsand its tests (yarn test-compiler-benchmarks);tests/compiler_benchmarks/data;compiler-benchmarks.A PR that already has the comment from #9253 gets a new one; the old one stops being updated.
For example, a slowdown that doesn't allocate:
Cost
The job takes about 3 minutes:
It finishes well before
build-compilerand the devcontainer job.New tests
In
scripts/allocBenchmarks.test.js:I refsline;🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gG86E3DicyC4NfsFGP