Skip to content

perf-bench: digest-only baseline re-record tool (tooling, unbreaking) - #770

Merged
d-q222 merged 1 commit into
mainfrom
agent/daniel-parent/perf-digest-merge-tool
Sep 16, 2026
Merged

d-q222 merged 1 commit into
mainfrom
agent/daniel-parent/perf-digest-merge-tool

Conversation

@d-q222

@d-q222 d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

What

Tooling/unbreaking, not a new feature: adds crates/perf-bench/scripts/merge_digests.py,
which copies only the named cases' digests from a freshly recorded
flashtex-perf-bench --json report into the committed baseline
(crates/perf-bench/baselines/linux-x86_64-ryzen7-7800x3d.json), leaving
metrics, meta (host_fingerprint, cpu, build_target, ...), schema_version,
targets, unmeasured, and every non-named case byte-identical. Also updates
crates/perf-bench/README.md with the re-record process for a PR author whose
change intentionally alters rendered output.

Why

engine performance is failing on ~10 open PRs. Two prior lanes established:

  • Its timing check never fires on GitHub's runner pool — it requires
    --require-same-host, which needs meta.host_fingerprint to match the
    pinned reference host (linux-x86_64-ryzen7-7800x3d), which no public
    runner is.
  • The only thing that can actually fail the gate is a byte-identical
    output-digest mismatch against the committed baseline.
  • 7 of the ~10 PRs legitimately change rendered output and trip it correctly.
    Each needs its affected digests re-recorded.
  • Digests are portable: they're sha256 hashes of rendered-output bytes only
    (cold.reply, export.pdf, per-keystroke warm-scenario reply hashes — see
    aggregate() in src/report.rs), with no timing/RSS/CPU input. Proved
    directly: a fresh --release recording on macOS/arm64 produced
    byte-identical digests for all 26 cases (214 digest entries, 0 differing)
    against the committed Linux/x86_64 baseline.

The gap: perf-bench had no way to update only digests. --json /
--update-baseline write a complete fresh report — digests and
metrics and meta. Using that here would silently overwrite the Ryzen
metrics and meta.host_fingerprint with macOS values, destroying the real
timing baseline and permanently disabling --require-same-host. This PR adds
a tool that closes that gap without touching anything but the named digests.

Design choices worth flagging

  • No bulk/"update everything" mode. Every case that should change must be
    named explicitly with --case; zero --case flags is a legitimate no-op
    (used by the round-trip check), never a shortcut. A blanket update is
    exactly how an unintended rendering regression gets laundered into the
    baseline — the digest gate's whole purpose is to force a human to look at
    each changed case.
  • Text splice, not re-serialize. Both files are the single-line, minified
    JSON the harness writes with alphabetically sorted keys. Rather than
    round-tripping through Python's json module (risking silently
    reformatting floats/whitespace/key order elsewhere in a 100+ KB line), the
    script locates the exact byte span of each named case's "digests": {...}
    value and splices it verbatim from the new report into a copy of the
    baseline text. Everything outside those spans is never re-emitted — it's
    copied straight through.
  • Refuses rather than guesses: mismatched case-id sets between the two
    files, a named case missing from either, or a case repeated on the command
    line all abort before anything is written. A self-check re-parses the
    merged output and confirms meta/schema_version/targets/unmeasured
    and every other case/field are still byte-identical, as a second line of
    defense on top of the splice approach itself.
  • Docs put the burden of proof on the author. A digest update is a claim
    that new rendered output is correct, not merely different. The README
    says plainly: justify per-case, in the PR, why the new output is right —
    "CI failed so I re-recorded" is not a justification.

Worked example (separate from this PR)

Applied to #699 (qed-glyph: QED mark is amsthm's \openbox, not the
glyph-less U+220E) as the worked example, in a commit pushed directly to that
PR's own branch (agent/daniel-parent/qed-glyph), not included here. Result
there: exactly lecture-notes's 10 digests changed (the document the perf
notes already flag as missing that glyph), metrics/meta untouched — see
that PR for the recording and the correctness justification.

Known unrelated breakage (not fixed here)

perf-bench's separate memprofile bin fails to link on macOS —
_malloc_trim is glibc-only:

Undefined symbols for architecture arm64:
  "_malloc_trim", referenced from: ... in memprofile-*.o
ld: symbol(s) not found for architecture arm64

The main flashtex-perf-bench binary is unaffected; every build in this PR
and in the #699 worked example used --bin flashtex-perf-bench. Not fixed
here (out of scope) — flagging in case it's worth its own issue.

Overlap check

Test results

$ python3 -m unittest discover -s crates/perf-bench/scripts -p 'test_*.py'
Ran 6 tests in 0.005s
OK

Round-trip proof against the real committed baseline (126,666 bytes, single
line):

$ python3 crates/perf-bench/scripts/merge_digests.py \
    --baseline baselines/linux-x86_64-ryzen7-7800x3d.json \
    --new-report baselines/linux-x86_64-ryzen7-7800x3d.json \
    --out /tmp/roundtrip-empty.json
cases compared: 26; cases named: 0
wrote /tmp/roundtrip-empty.json

$ diff baselines/linux-x86_64-ryzen7-7800x3d.json /tmp/roundtrip-empty.json && echo IDENTICAL
IDENTICAL
$ cmp baselines/linux-x86_64-ryzen7-7800x3d.json /tmp/roundtrip-empty.json && echo "cmp: byte-identical"
cmp: byte-identical

One-case proof, against a real macOS --release recording of this repo's own
corpus (lecture-notes, the same recording used for #699):

$ python3 crates/perf-bench/scripts/merge_digests.py \
    --baseline baselines/linux-x86_64-ryzen7-7800x3d.json \
    --new-report /tmp/qed-glyph-macos-report.json \
    --case lecture-notes --out /tmp/one-case.json
cases compared: 26; cases named: 1
  lecture-notes.cold.reply: 9104d5a2d6ee77cd -> eb933cdcf0393e8a
  lecture-notes.export.pdf: d759d692bfa079c3 -> 04d6c9cf338e1b97
  lecture-notes.warm.delete-restore-line.v1: cfd0c52a61a66282 -> 2d43b7f4f22bba29
  lecture-notes.warm.delete-restore-line.v2: 7165dd81449ce3cd -> e867cbbdee4aba12
  lecture-notes.warm.type-display-eq.v1: 9f17253c299e520d -> 27ea16f63278a979
  lecture-notes.warm.type-display-eq.v2: bdc123b000bfc833 -> 0c1a2c6fe124adac
  lecture-notes.warm.type-inline-math.v1: edc9a0a3ed3590de -> d220480647efc76d
  lecture-notes.warm.type-inline-math.v2: 2c34ec00f60524e8 -> c745ff2e6dd1380e
  lecture-notes.warm.type-paragraph.v1: ef36ea4c6af54821 -> 02c5ba7178907f81
  lecture-notes.warm.type-paragraph.v2: 2a46449d4a8d7b32 -> 35c0ee7e19898ee7
wrote /tmp/one-case.json

Independently verified (separate script, not the tool's own report) against
the pre/post files: schema_version/meta/targets/unmeasured equal, the
other 25 cases equal in full, and case lecture-notes equal in every field
except digests.

Not done

  • The other ~6 PRs with legitimate rendering changes: intentionally not
    touched here — each needs its own author's correctness judgement, per the
    task instructions. Handing those out separately.
  • memprofile's macOS link failure: noted above, not fixed (unrelated,
    out of scope).
  • Not merged to main.

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

What changed:
`engine performance` was failing on ~10 open PRs. Two prior lanes established
the CI gate's TIMING checks never fire on GitHub runners (--require-same-host
never matches the pinned linux-x86_64-ryzen7-7800x3d host), so the ONLY thing
that can actually fail is a byte-identical output-digest mismatch against
crates/perf-bench/baselines/linux-x86_64-ryzen7-7800x3d.json. Several open PRs
legitimately change rendered output and trip that correctly - they need their
affected digests re-recorded, but perf-bench had no way to do that without
`--json`/`--update-baseline` overwriting the whole report, including the
Ryzen-only `metrics` and `meta.host_fingerprint`, which would silently destroy
the timing baseline and disable --require-same-host forever.

Adds crates/perf-bench/scripts/merge_digests.py: copies ONLY the named cases'
`digests` from a freshly recorded report into the committed baseline via a
text splice (not a re-serialize), leaving metrics/meta/schema_version/
targets/unmeasured and every non-named case byte-identical - verified both by
construction and by a self-check before it writes. No case list defaults to
"update everything"; every case must be named explicitly with --case, and
zero --case flags is a legitimate no-op, not a shortcut. Refuses to run if
the baseline/new-report case-id sets differ, if a named case is missing from
either, or if a case is repeated on the command line.

Documents the re-record process in crates/perf-bench/README.md: digests are
portable (proven separately: a full macOS/arm64 recording matched the
committed Linux baseline byte-for-byte across all 26 cases/214 digest
entries), metrics/meta are not and must never be regenerated off the pinned
reference host, and a PR author re-recording digests must justify in the PR
why the new rendered output is correct - a digest update is a claim of
intent, which is the entire reason the gate exists.

Applied as a worked example to #699 (qed-glyph) in a separate commit/push to
that PR's own branch, not included here.

Known unrelated breakage, noted but not fixed here: perf-bench's separate
`memprofile` bin fails to link on macOS (`_malloc_trim` is glibc-only); the
main `flashtex-perf-bench` binary is unaffected. Worked around throughout by
building with `--bin flashtex-perf-bench`. Confirmed by reproduction:
`cargo build --release --bin memprofile` -> "Undefined symbols ... _malloc_trim
... ld: symbol(s) not found for architecture arm64". Probably worth its own
issue; not filed here to stay in scope.

What was run:
- python3 -m unittest discover -s crates/perf-bench/scripts -p 'test_*.py':
  Ran 6 tests in 0.005s, OK (round-trip identity, single-case merge leaves
  meta/other-case/other-fields untouched, and all three refusal paths:
  mismatched case-id sets, unknown --case, duplicate --case).
- Manual round-trip proof against the real 126 KB committed baseline (self
  vs self, 0 cases): `diff`/`cmp` both report byte-identical.
- Manual one-case proof against a real macOS --release recording of this
  repo's own corpus (case `lecture-notes`, the #699 worked example): only
  that case's 10 digest keys changed; independently verified (separate
  script, not the tool's own report) that schema_version/meta/targets/
  unmeasured and every other case/field were untouched.

Next step:
Commander/reviewers hand out the remaining ~6 PRs with legitimate rendering
changes to their respective authors, each re-recording with this tool and
justifying their own case(s) in their own PR.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
d-q222 added a commit that referenced this pull request Sep 16, 2026
…699)

What changed:
This PR (agent/daniel-parent/qed-glyph, #699) intentionally changes how a
proof's QED mark renders: amsthm's `\openbox` (four drawn rules) instead of
the glyph-less U+220E, which has no glyph in the shipped fonts. That is
exactly the rendering path `lecture-notes` exercises, so its 10 output
digests (cold.reply, export.pdf, and 8 warm-scenario reply hashes) change;
every other case's digests, and all `metrics`/`meta`, are untouched.

Re-recorded with the new digest-only merge tool from #770 (see that
PR for the full mechanism and rationale):

  cargo build --release --bin flashtex-perf-bench   # CARGO_TARGET_DIR=target-perfdigest, CARGO_BUILD_JOBS=4
  ./target/release/flashtex-perf-bench --json /tmp/report.json
  python3 crates/perf-bench/scripts/merge_digests.py \
      --baseline crates/perf-bench/baselines/linux-x86_64-ryzen7-7800x3d.json \
      --new-report /tmp/report.json --case lecture-notes \
      --out crates/perf-bench/baselines/linux-x86_64-ryzen7-7800x3d.json

Recorded on macOS/arm64 (not the pinned Ryzen/Linux reference host), which is
fine for digests specifically: they hash only rendered-output bytes, with no
timing/RSS/CPU input, and were independently confirmed portable (a full
26-case, 214-digest recording on this machine matched the committed Linux
baseline byte-for-byte except for these exact 10 entries). `metrics`/`meta`
(host_fingerprint, cpu, build_target, ...) are untouched — this machine's
numbers were never written anywhere near the committed file.

What was run:
- Full-corpus recording (26 cases, release build): 214 digest entries total,
  25 of 26 cases unchanged, only `lecture-notes` differs, in exactly the 10
  keys listed above (diffed independently with a separate script, not just
  the merge tool's own report).
- merge_digests.py's built-in self-check (schema_version/meta/targets/
  unmeasured/every other case/every other field of this case all
  byte-identical before it would write) passed.
- `--print <new report> --baseline <updated baseline>`: no digest mismatch
  reported for any case (the only FAIL shown is an unrelated font-path
  timing warning between two macOS runs' font_dirs, irrelevant to the
  digest gate and irrelevant on CI, where --require-same-host means the
  timing checks never fire on GitHub's runner pool anyway).

Next step:
CI's `engine performance` digest check should now pass on this PR. Timing
metrics/meta remain the original Ryzen/Linux baseline, so --require-same-host
continues to gate correctly wherever it can actually fire.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222
d-q222 merged commit 0a36fee into main Sep 16, 2026
21 of 22 checks passed
@d-q222

d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Merged to main in integration batch B (12f2f0ba), alongside #699 as the worked example.

Verified before the push: cargo test --release --no-run as a separate first step (clean compile), then --release --no-fail-fast → 486 passed, 0 failed, 4 ignored on render-pipeline — up from 484, so nothing was lost.

Confirmed on origin/main: crates/perf-bench/scripts/merge_digests.py and test_merge_digests.py are present, and this branch's head is an ancestor of main.

Closing manually — GitHub had not yet auto-closed it, since the content landed via an --no-ff integration merge rather than a PR merge.

d-q222 added a commit that referenced this pull request Sep 16, 2026
…ately changes

19 of 26 cases' digests move (167 keys total: cold.reply, export.pdf, and
the warm-scenario reply hashes) -- every case that contains math using
family-0 characters (digits, \sin/\lim-style operators) without lmodern,
which is where this branch's fix (cmr, not rm-lmr, for family 0 absent
lmodern) actually changes rendered box heights. Several non-math-specific
warm scenarios (warm.type-paragraph) also move for documents that contain
math elsewhere: the fix changes a display's box height, and per the PR's
own description every baseline below that box rises with it, so a later
page's plain-paragraph digest reflects the same document-wide reflow.

Unaffected, as expected: cv, letter, listings-manual, unicode-accents,
tikz-heavy (no math using family-0 characters), lmodern-report (already
uses rm-lmr via \usepackage{lmodern}, unaffected by this fix by design),
inline-math (contains math, but not the specific family-0 glyphs this fix
touches).

Verified with crates/perf-bench/scripts/merge_digests.py (#770): only the
named cases' digests changed; schema_version/meta/targets/unmeasured and
every other case/field byte-identical (self-check plus an independent
post-merge diff). metrics/meta.host_fingerprint untouched -- still the
pinned Ryzen/Linux reference host, since digests are portable but timing
is not. Re-ran --check against the updated baseline: OK, 549 metrics
compared, no regression.
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