Skip to content

Validate in ~3 minutes, gate every output parity suite and the instruction count - #99

Merged
open-session-submodule[bot] merged 5 commits into
ocaml-to-rust-rewritefrom
ci-speed-icount
Nov 11, 2026
Merged

open-session-submodule[bot] merged 5 commits into
ocaml-to-rust-rewritefrom
ci-speed-icount

Conversation

@jfrolich

@jfrolich jfrolich commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

What

CI changes for pull requests against ocaml-to-rust-rewrite: the validation workflow drops from about 20 minutes to about 3, every output parity suite of the Correctness Contract gates a change, and a new check fails PRs that make the compiler execute more instructions.

Validation workflow

It used to be one job of about 20 minutes. Most of that time went to three cold release builds with fat LTO, run one after another; every parity step then set up OPAM and built the OCaml reference compiler.

job starts does
build at once release rescript without LTO, uploaded as an artifact
ocaml at once OCaml bsc and res_parser, cached by their sources; OPAM is set up only on a miss
compiler-tests at once builds the compiler tests (dev profile), waits for both artifacts, builds the OCaml fixtures, runs the tests
build-system-tests at once cargo test --release for rewatch; saves the release cache
script-tests at once the parity scripts' own tests, in parallel
compiler-warnings at once warning-free Clippy and rustdoc for the compiler crate (from trunk), now on Arm with a trunk-saved cache
parity (javascript) after build, ocaml JavaScript output, CLI output filenames, marshal flags (gating)
parity (diagnostics) after build, ocaml errors and warnings (gating)
parity (stdlib) after build, ocaml runtime JavaScript output (gating, new in CI)
parity (gentype) after build, ocaml genType output of the two in-repo suites (gating, new in CI)
ir-parity (typedtree / raw-lambda / lambda) after build, ocaml diagnostic only
  • Arm runners. ubuntu-24.04-arm built the same release in 194 s against 238 s on x64.
  • Warm Rust caches. Trunk runs save the release and compiler-test target directories with rustc's incremental state. Cargo decides freshness by file contents (CARGO_UNSTABLE_CHECKSUM_FRESHNESS, the toolchain is a pinned nightly), not by the mtimes a fresh checkout sets, so a PR recompiles only what it changed.
  • No LTO in these builds: it does not change behaviour, and nothing ships from them.
  • Parallel diagnostic parity. scripts/test_error_output_parity.sh now runs its cases PARITY_JOBS at a time (default: the CPU count; 1 keeps the old behaviour), keeping each case's OCaml and Rust commands in order and comparing in the original order. Locally 95 s → 17 s, on CI 56 s → 19 s, with the same results; a new test checks serial and parallel runs report the same failures.
  • genType parity needs the private Tella checkout for its third suite, so CI sets GENTYPE_PARITY_WITHOUT_TELLA=1, which skips only that suite and says so.

Measured on this PR (caches saved by its own earlier run, as trunk runs will save them):

run wall
before this PR ~20 min
warm, with a one-line edit in lambda/lam_compile.rs 3 min 15 s (build 99 s, compiler tests built in 47 s, parity jobs 30–70 s after the build)
cold (no caches, OPAM never installed on Arm) 7 min 40 s

The first trunk run after merging is a cold one and saves the caches.

Instruction count

A new Instruction count workflow fails a PR that makes the compiler execute more instructions. It builds the PR's rescript and its base's like a release (fat LTO, one codegen unit), then counts with cachegrind the instructions of a clean single-threaded tests/tests build with each, five runs per side, keeping the smallest.

  • The check fails when the PR is more than 0.1% above its base. On CI, runs of one executable vary by about 0.08%; identical code on both sides measured +0.010%, +0.018% and −0.009%. GitHub's runners have no hardware counters (perf: "instructions:u event is not supported").
  • Both checkouts sit at paths of the same depth: at different depths, identical code differed by +0.09%, mostly in path handling.
  • Both sides build the base's tests/tests, so a PR that adds tests is not counted as slower. Each side uses its own embedded runtime.
  • The job summary shows both counts and the functions whose counts moved most (cg_annotate --diff).
  • Trunk runs cache each commit's executable, so a PR usually builds only its own; otherwise a parallel job builds the base's.
  • To accept an increase, add an Instruction-count-increase: <why> trailer to one of the PR's commits (parsed with git interpret-trailers, so only a real trailer counts).
  • It stays on x64 and takes about 10 minutes, mostly the fat-LTO builds; on Arm those were slower (416–456 s against ~355 s).

Verification

This PR's own runs use the changed workflows: all checks pass, cold and warm.


Started by Jaap Frolich in this Assistant session

@jfrolich
jfrolich force-pushed the ci-speed-icount branch 4 times, most recently from b8f4479 to 2898161 Compare November 11, 2026 19:44
@jfrolich jfrolich changed the title Run validation as parallel jobs and gate PRs on instruction count Validate in ~3 minutes, gate every output parity suite and the instruction count Nov 11, 2026
open-session-submodule Bot and others added 5 commits November 11, 2026 20:46
The validation workflow ran everything in one 20-minute job on one
runner. Most of it was compiling: the compiler test binary, the build
system test binaries and the rescript executable, each fat-LTO-linked
and each built one after another.

Now the build job makes one rescript executable without LTO and hands
it to the compiler tests, the gating parity suites (JavaScript and
diagnostics) and the diagnostic-only IR parity suites, which run on
their own runners. The build system tests compile on another runner
from the start. LTO does not change behaviour, and nothing ships from
these builds; the Instruction count workflow builds the shipped
configuration.

Rust dependencies are cached with rust-cache (saved by trunk runs),
which keeps only the compiled dependencies, the part a fresh checkout
can reuse. The parity scripts' own tests move to the build system
test job, which finishes before the parity jobs and needs no executable.

Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://jakes-mac-mini.tail23a77e.ts.net:8443/session/os-01a1cb83-dc2c-7699-ae5b-a6cbc18944ef
Signed-off-by: Jaap Frolich <jfrolich@gmail.com>
A new workflow builds the pull request's rescript and its base's with
fat LTO and one codegen unit, then counts the instructions a clean
single-threaded build of tests/tests executes with each, under
cachegrind (GitHub's runners expose no hardware counters). It fails
when the pull request's count is more than 0.1% above the base's.

Why 0.1%: four clean builds with one executable on CI varied by 0.08%
(4,635.9 to 4,639.5 million instructions); the comparison takes the
smallest of five runs per side. Both checkouts sit at paths of the same
depth: with the checkouts at different depths, two builds of the same
code differed by +0.09%, mostly in path handling. One codegen unit keeps
the count from moving with how the code happens to be partitioned,
which on 16 units was about 1% between equivalent builds.

Both sides build the base's tests/tests, so pull requests that add tests
are not measured as slower, and each uses its own embedded runtime.
Trunk runs cache the executable of each commit, so a pull request
usually builds only its own. An increase is accepted by a trailer
`Instruction-count-increase: <why>` on one of the pull request's commits.

Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://jakes-mac-mini.tail23a77e.ts.net:8443/session/os-01a1cb83-dc2c-7699-ae5b-a6cbc18944ef
Signed-off-by: Jaap Frolich <jfrolich@gmail.com>
The Correctness Contract in AGENTS.md names four output parity suites:
JavaScript, stdlib, genType and diagnostics. CI ran only JavaScript and
diagnostics, both in one job, so a pull request showed one red parity
check without saying which suite failed, and runtime and genType output
were not checked at all.

The parity job is now a matrix with one check per suite: javascript
(with the CLI output filename and marshal checks), diagnostics, stdlib
and gentype. They run side by side after the build job and finish
before the compiler tests, so the workflow takes no longer.

The genType script always includes the Tella suite, which needs a
private checkout. GENTYPE_PARITY_WITHOUT_TELLA=1 runs the two in-repo
suites only and says so in the output; CI sets it.

Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://jakes-mac-mini.tail23a77e.ts.net:8443/session/os-01a1cb83-dc2c-7699-ae5b-a6cbc18944ef
Signed-off-by: Jaap Frolich <jfrolich@gmail.com>
The diagnostic parity script ran its 2,101 cases one after another,
about 4,200 compiler processes, and forked tr and cat several times per
case around them: 95 s on the Mac mini, 56 s on CI.

With PARITY_JOBS above 1 (the default is the number of CPUs) the case
loops first queue each case's OCaml and Rust commands as one task, run
the tasks PARITY_JOBS at a time with xargs, then compare the captured
outputs in the original order. A case's two commands still run one
after the other, and the packages and interfaces cases need are still
prepared serially before any task runs. PARITY_JOBS=1 keeps the old
one-case-at-a-time behaviour. Safe names, exit statuses and queued
commands now use bash builtins instead of subshells and tr.

Locally the suite takes 17 s instead of 95 s, with the same summary. A
new test runs the compiler cases with fake compilers at PARITY_JOBS=1
and 4 and checks that both report the same failures.

Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://jakes-mac-mini.tail23a77e.ts.net:8443/session/os-01a1cb83-dc2c-7699-ae5b-a6cbc18944ef
Signed-off-by: Jaap Frolich <jfrolich@gmail.com>
The validation workflow took about 10 minutes: a cold release build of
rescript (4-5 min, since Cargo rebuilds this repository's crates after a
fresh checkout whatever is cached), then the compiler tests, which also
compiled their crate from scratch, and every parity job spent 40-50 s
installing OPAM and building the OCaml reference compiler.

Now:

- Jobs run on ubuntu-24.04-arm, where the same release build took 194 s
  against 238 s on x64.
- The release and compiler-test target directories are cached by trunk
  runs with rustc's incremental state, and Cargo decides freshness by
  file contents (-Zchecksum-freshness) rather than the checkout's
  mtimes, so a pull request recompiles only what it changed.
- An ocaml job builds just the OCaml bsc and res_parser and caches them
  by the hash of the sources dune builds them from. OPAM is set up only
  when that cache misses; the parity jobs take the executables as an
  artifact.
- The compiler tests compile from the start and wait for the build and
  ocaml jobs' artifacts only before running, and build in the dev
  profile: the tests run in half a second, building them is the cost.
- The build job only builds and uploads; the build system tests rebuild
  the same release target on their own runner and save its cache, so the
  parity jobs do not wait for the tests or the cache upload.
- The parity scripts' self-tests run in parallel in their own job, and
  the three diagnostic-only IR suites are a matrix like the gating ones.

The Instruction count workflow stays on x64: its fat-LTO, one-unit
builds took 416-456 s on Arm against about 355 s on x64.

Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://jakes-mac-mini.tail23a77e.ts.net:8443/session/os-01a1cb83-dc2c-7699-ae5b-a6cbc18944ef
Signed-off-by: Jaap Frolich <jfrolich@gmail.com>

@open-session-submodule open-session-submodule Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent review of the five commits at 4159d91 (I did not write this change).

  • No gate is weakened. JavaScript and diagnostics parity run the same scripts with the same flags as before; stdlib and genType parity are new gating checks. The typedtree and Lambda suites stay continue-on-error, as the Correctness Contract describes them.
  • Parallel diagnostics parity. Each case's OCaml and Rust commands stay in order inside one task, packages and cached interfaces are still prepared serially before any task runs, the comparison walks the cases in the original order, and a command with no captured status falls back to running directly. Stale .status files are deleted at start-up, so a result cannot come from an earlier run. The new test checks that serial and parallel runs report the same failures, including a differing output and a timeout.
  • GENTYPE_PARITY_WITHOUT_TELLA=1 skips only the third suite and prints that it did; without the variable the script still refuses to run without that checkout.
  • OCaml reference cache. The key covers every .ml, .mli, .c, .h and dune file under compiler, which is everything rescript_compiler_main.exe and res_cli.exe are built from.
  • Instruction count. Both sides build the parent's tests/tests from checkouts at equal path depth, the smallest of five runs is compared, and only a real Instruction-count-increase: trailer accepts an increase. Trunk pushes report without failing.

One thing to be aware of, not blocking: the compiler tests now run in the dev profile instead of --release.

All 16 checks pass. No compiler source changes, so generated output cannot move.

@open-session-submodule
open-session-submodule Bot merged commit 4740a90 into ocaml-to-rust-rewrite Nov 11, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant