Browse documentation

Each PR benchmark run measures another code layout of each build

Date: 2026-12-02 Area: ci, tooling, benchmarking Issue: #1917 Related: refines ADR 0240, ADR 0165

Context

ADR 0240's comparison marks a benchmark when every PR run sits outside every main run and the medians differ by more than the wider of the two builds' run-to-run ranges. Each build ran as one binary, so its five runs measured one placement of its code. A change to compiled code moves the code after it, and the benchmarks that run that code speed up or slow down without doing more or less work (#1917). One binary per side shows such a shift as a consistent difference, and the comparison marked it:

  • #2546, which changes no engine code, got 46 marks of 1.2% to 17%.
  • A procedure that nothing calls, added near the start of Goccia.VM (probe #2559, never merged), got 122 marks: 69 🟢 and 53 🔴, up to 15%.
  • A few steps of extra work in String.prototype.repeat and trim (probe #2561, never merged) got 21 marks, and only string repeat (−12.2%) is that work. trim operations read −1.7%, while float16array.js slice() read −41%.

main's five runs of string repeat lay within 0.3% of each other on one binary. Its five layouts below spread over 8% to 13%. The old engine's ./build.pas --layout-probe built one placement control; it left with the old engine (#2187). GitHub's hosted runners cannot count instructions, which would separate work from placement directly (ADR 0165).

Decision

A build is measured over five layouts of its code. scripts/layout/ld.bfd is the linker FPC calls when a build passes -FDscripts/layout. It links the program unchanged and, for each seed in GOCCIA_LAYOUT_SEEDS, once more as <program>-layout<seed>. FPC puts each procedure in a section of its own (.text.n_<name>). For a seed, the procedure section whose name hashes lowest with the seed asks for a 4096-byte alignment in a copy of its object, and --section-start keeps .text where it starts in the program as linked. The linker pads 0 to 4095 bytes in front of that procedure, so the code from there on moves and the code before it stays. That is what a change that inserts code at one place does. Only that one section header changes. Each object's instruction bytes are the same, and only relocated operands, such as call displacements, take the new addresses. The padding never runs. A seed picks the same procedure in every build that has it, unless a build adds a procedure that hashes lower. A procedure already on a 4096-byte boundary moves nothing, and one an earlier seed took repeats its layout, so the seed takes its next procedure; the wrapper checks that each layout's code differs from the program's. The same objects and seeds give the same binaries.

Run r of both builds is layout r. The benchmark-layouts job builds main's and the PR's benchmark runner, each with the PR's toolchain.lock and wrapper, and links the seeds BENCHMARK_LAYOUT_SEEDS names, 1 to 4, beside each. scripts/benchmark-ab.js takes a build as several binaries and runs repetition r on its binary r: the binary as built, then the four layouts. A benchmark's range then covers five placements of its code, so a change within the range the layouts moved it is not marked. A file the time budget cuts short has fewer runs, and so fewer layouts. The marking rule is ADR 0240's, unchanged. The comment says that its runs are layouts. When either side's layouts are missing, both run as one binary as before, and the comment says a mark may then be placement.

Considered: giving every procedure a seeded alignment of 16, 32 or 64 bytes. On the first three probes below it marked 0 of 455 each time, with median floors of 4.4% to 8.7%. On a small test program it grew .text by about 7%, because the padding is spread over every procedure. One insertion point models a change and adds at most 4 KiB.

Measurements

Probe PRs on ubuntu-latest, never merged, with the full benchmark job: the one-binary column on main's workflow, the layouts column with this wrapper as merged (.text kept, distinct layouts) on this one. Marks are of 455 benchmarks; the numbers are GitHub Actions run IDs.

ProbeOne binary per buildFive layouts per build
No compiled change0 (#2547, ADR 0240)0 (#2557, 47000710041)
Procedure nothing calls, in Goccia.VM122 (#2559, 46981630676)1, −3.8% (#2558, 47000717109)
8 steps more in repeat and trim21, string repeat −12.2% among them (#2561, 46981645301)0; string repeat −2.6% and trim operations −6.2% read ~ (#2560, 47005026262)
64 steps more in repeat and trim98, string repeat −40.7% and trim operations −68.1% among them (#2561, 46993277806)2, string repeat −47.2% and trim operations −76.2% (#2560, 47000720384)

Median floor per run: 2.6% to 4.8% on one binary, 7.2% to 14.3% over layouts. The 90th percentile is 8% to 17% on one binary and 17% to 29% over layouts. Every layout run has single runs 29% to 59% below a benchmark's median, some on the binary as built: float16array.js slice() ran at 0.53M ops/s against about 0.89M in one. The padding makes no layout slower as such: run 0 (the binary as built, and each file's first run) averaged −0.94% to −2.53% from a benchmark's median, and the seeded runs −1.94% to +0.78%.

Each layout does the same work. Counted with perf stat -e instructions:u on an x86-64 Linux machine, a deterministic profile run of benchmarks/strings.js retired 72,019,295 to 72,024,856 user instructions over the five layouts, two runs each, and benchmarks/arrays.js 80,055,366 to 80,061,132: the same spread as two runs of one binary.

Consequences

  • A mark means a difference larger than both builds' ranges over their layouts, which include how far those layouts moved the benchmark. Five layouts sample placement rather than bound it, so a mark can still be placement: the procedure that nothing calls got one. A smaller change reads ~, however real it is, and its floor in brackets says how large a change would show. The 8-step slowdown (−12.2% on one binary) is such a change. The floors are two to three times ADR 0240's, and a benchmark with one far-off run has a floor to match. Placement moves benchmarks that far, so a smaller mark could not tell work from placement.
  • The benchmark job's time does not change: the runs are the same five a side. The two benchmark-layouts legs take about 1.5 to 2 minutes each, in parallel, and end before build, so a PR's CI takes no longer. They add about 3.5 runner-minutes and two artifacts of five binaries each.
  • The wrapper needs Linux, ELF64 objects and node. The comparison runs on ubuntu-latest. build-main still builds main's runner for the profile diff and the AWFY and JetStream lanes.
  • A local A/B can use the same layouts: benchmark-ab.js takes each, and a layout of GocciaRunner against the binary as built is a placement control for the AWFY driver, as --layout-probe was for the old engine (Code layouts).