Skip to content

FT-070 memory: measure the breakdown, derive the per-glyph carets (Cluster 160 -> 88 B) - #232

Merged
GoKubar merged 13 commits into
mainfrom
agent/linux-primary/ft070-memory
Sep 15, 2026
Merged

GoKubar merged 13 commits into
mainfrom
agent/linux-primary/ft070-memory

Conversation

@GoKubar

@GoKubar GoKubar commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

FT-070 asked where 4931 MiB of steady memory goes on a 2 MB document against a
100 MB target. This measures it per structure, removes the largest piece of
provable duplication, and reports what the arithmetic then says about the
target.

Based on main @ 62200c0 with PR #206's harness merged in (the memory work
measures with it). The two call sites that stopped #206 building against
current main are fixed here and reported on that PR.

1. Where it actually goes

New instrument: render_pipeline::memsize walks a built display list and
render cache and charges allocated bytes (capacity, not length) to named
lines, counting each shared Rc once. crates/perf-bench gains a
memprofile binary that renders a corpus case through the product path, runs
the harness's warm keystrokes, and reports VmRSS alongside live bytes from a
counting global allocator — so the gaps are separated rather than guessed.

synthetic-2mb, 1507 pages, 1.48 M glyphs, before any change:

bucket MiB % RSS
allocator retention + fragmentation (RSS − live) 1114 40%
render cache (walked) 801 29%
live but not reachable by the walk (font, expander, compiler caches) 502 18%
display list (walked) 365 13%
VmRSS 2781

A malloc_trim(0) probe splits the first row: 436 MiB was trimmable free
arena
, the other 678 MiB is real fragmentation — the cost of 1.48 M
small allocations in ~300 k separate vectors, not an independent bug.

The walked 1165 MiB, biggest lines first:

structure MiB count
AssembledBlock cluster vectors (the cache's second copy) 238.0 1 400 343
RenderCache.blocks BuiltBlock.items 160.2
Cluster.carets 101.6 1 479 944
RenderCache.assembled spine 88.2 30 361
Page.items (Item is 200 B) 80.9 306 740
RenderCache.blocks ClusterRec 73.1
RenderCache.blocks BoxRec slots 61.0
AssembledBlock glyph vectors 59.5 1 400 343
GlyphRun.glyphs 56.5 1 479 944
Cluster.provenance 56.5 1 479 944
RenderCache.adapted 52.3 22 764
Cluster.hit_rect 45.2 1 479 944

The Mac wire lane's finding does not transfer to resident memory the way it
reads.
Per-glyph carets/hit_rects/sources are ~55% of display-list bytes
and really are 90% of a Cluster in memory — but the whole display list is
only 13% of RSS. Per-glyph data across both copies (display list and cache)
is 580 MiB: 21% of RSS, 50% of walked bytes. Real, but not the whole gap.

2. What changed

Cluster carried Carets { first: Caret, last: Option<Caret> } — 72 of its
160 bytes — and a text run emits one cluster per glyph. That data was never
independent:

carets.first == Caret { text_byte: text_start_byte,
                        x: hit_rect.x, top: hit_rect.top, height: hit_rect.height }

at all three construction sites (text runs, math, TikZ node text), and
place_item/shift_x moved the rect and both carets by the same offset, so
placement preserved it too.

Audited before touching anything, over the twelve measurable corpus cases —
1 991 552 clusters:

  • start caret byte-identical to the derived one: 1 991 552 / 1 991 552;
  • end caret on a cluster other than its run's last: 0;
  • end caret top/height differing from that cluster's hit rect: 0.

So the carets are derived, and the one genuinely non-derivable part — the end
caret's x (the TikZ path clamps the hit rect's width to one tick but not the
caret) and its text byte — moves to the run as GlyphRun::end_caret, one per
run instead of 40 bytes per glyph. Cluster: 160 → 88 bytes.

This also makes structural an invariant join_runs used to maintain by hand:
it cleared the joined-over cluster's trailing caret so only a run's last
cluster carried one. With the caret on the run there is nowhere for a mid-run
one to live.

Both JSON writers and the delta digest call GlyphRun::carets_of, which
rebuilds the same Carets. delta::changed_items compares end_caret once
per run instead of carets per cluster — the same comparison, since the rest
of the caret is the cluster bytes and hit rect it already compares.

3. Before / after

memprofile, one render plus warm keystrokes in one process (allocator-
independent, since it reports live bytes):

500 KB (385 pp) 2 MB (1507 pp)
before after before after
VmRSS 703.3 651.1 2780.9 2569.6
VmRSS after malloc_trim 593.1 541.0 2344.7 2133.8
live 419.0 367.8 1667.1 1458.4
walked 289.9 238.7 1165.4 956.7
— display list 90.8 65.7 364.7 263.1
— render cache 199.1 173.1 800.7 693.6

−12.5% of live bytes and −7.6% of RSS at 2 MB; −12.2% / −7.4% at 500 KB.

Harness steady RSS at 2 MB: 5109 → 4905 MiB, peak 5764 → 5475. At
500 KB the harness's single-sample steady RSS moved 2477 → 2625 while its peak
fell 2682 → 2630; that row is allocator retention noise (the same run trims
436 MiB on demand), which is why the table above is the number to read.

4. Output identity

Every fixture digest is unchanged — that was the hard gate.

  • 90 digests across all 12 measurable corpus cases, 0 differing, each
    compared against a run of the same base commit (f79212ee), not against
    the committed baseline (which predates current main and differs on six math
    cases for reasons unrelated to this change). Includes cold.reply (the full
    display-list JSON), every warm scenario in v1 and v2, and export.pdf.
    Page counts and label passes identical.
  • article-twocolumn and input-bibliography remain unmeasurable for missing
    ectt*.tfm; the committed baseline records them as unmeasured for the same
    reason.

Gates:

  • amsmath 59/59 within 0.5 bp against the pdflatex oracle.
  • HW1 and HW2: 3 pages, 0 errors, 0 overfull, 0 font diagnostics each.
  • cargo test -p flashtex-render-pipeline --no-fail-fast: 186 passed, 3
    failed
    , identical pass count and identical failing set to a control run of
    the same base — font_family_fixtures_match_pdflatex,
    footnotes_against_pdflatex, page_frame_against_pdflatex (all pre-existing).

Zero font diagnostics in every benchmarked render.

5. What dominates next, and the honest read on the target

After this change, at 2 MB: allocator 1111 MiB, render cache 694 MiB, unreached
495 MiB, display list 270 MiB.

The 100 MB target is not reachable by representation alone. 1507 pages ×
1.48 M glyphs: even at a perfect 40-byte glyph and a 64-byte cluster with zero
duplication, the display list alone is ~154 MB, already over target, before the
cache, the box tree or the page item slots. 100 MB across 1507 pages is ~68 KB
per page — less than one page's glyph data at any representation that keeps
per-glyph carets and source ranges. Reaching it means not holding every page's
display list at once (materialise a page window, keep layout records for the
rest), which is an API change and belongs in its own PR.

Follow-ups, each measured here and each its own PR:

  1. Share the assembled items with the pages — Page.items are clones of
    AssembledBlock.lines items differing only by an x shift. Holding one copy
    behind an Rc with a per-item dx removes ~386 MiB at 2 MB. Changes
    Item's public shape.
  2. SourceRange.path: Rc<str> → a u32 document index into a path table.
    The Rc is literally one allocation for the whole document, re-pointed
    1.48 M times; with Provenance's String/Vec variants boxed this takes
    Cluster 88 → 64 and removes ~35 MiB. Public API.
  3. Bound the render cache by bytes. MAX_BLOCKS is 50 000 entries with no
    byte budget, cleared wholesale; at 1507 pages it holds the document roughly
    three times (layout records, assembled items, adapted items) without ever
    reaching the cap. This is eviction, not representation, so it is listed last
    — but it is 27% of RSS.
  4. Fragmentation (678 MiB, 24% of RSS) should fall out of 1 and 2; worth
    re-measuring rather than attacking directly.

Notes

The box is shared — other lanes were building throughout. Load average was
4–13 across these runs, which is why timings here are not offered as evidence;
memory is far less noisy and the digest comparison is load-independent.

claude and others added 6 commits September 13, 2026 16:10
There was no way to tell whether an engine change made the compiler faster.
The numbers that existed came from `examples/stages.rs` and `perf_bench.rs`:
macOS-only metadata, one sample per cell, no memory figure, no machine-readable
output, and no way to fail a build on a regression. This adds a harness whose
output can be argued with.

`crates/perf-bench` measures the product path -- the same
`protocol::handle_line` the `flashtex-render` worker serves -- over the ten
committed real-world fixtures and four generated documents (500 KB, 2 MB,
math-heavy, TikZ-heavy; generators committed, not blobs). Per case it reports
cold timings with a per-phase split, warm single-keystroke timings, PDF export,
peak and steady RSS, and an output digest. `--baseline ... --check` turns the
same run into a CI gate.

Three rules the harness enforces on itself, because breaking any of them
produces numbers that look fine and mean nothing:

* No measurement without fonts. Latin Modern and the pinned 12 pt TFM set must
  load and no render may substitute a face or a metric, or the case produces no
  timing at all -- a substituted metric is a different workload, not a slower
  one. The font set is built with `FontSet::with_dirs`, which probes nothing,
  so this box's TeX Live cannot supply the metrics by accident. The line is
  drawn at the configuration, not the document: a character with no glyph, or a
  class command the compiler does not model, is deterministic and identical
  every run, so the case is measured and the degradation is recorded next to
  the number.
* Cold means cold. Every repetition runs in a child process of its own, so the
  expander's thread-local cache, the font set's memoised faces and the
  allocator all start empty, and peak RSS belongs to one document.
* Medians, with the spread shown. Nothing comes from one sample; every metric
  carries n, p25/p75, p95 and MAD, and the table prints the run's own noise
  estimate per case.

The gate is built to survive a shared machine. A metric counts as regressed
only when it exceeds both the tolerance and that metric's own measured spread
in the baseline, and the comparison warns and stops enforcing timings when the
host, build profile, font configuration or peak load differ. Output identity
does not depend on the machine -- the fonts come from the repository -- so a
changed digest fails everywhere and unconditionally.

Baseline, at main 8465bbd on a Ryzen 7 7800X3D: cold HW1 meets its 10 ms
target; warm keystroke is 153x over budget at 500 KB and 132x at 2 MB, HW1 PDF
export is 5.6x over, and steady memory at 2 MB is 49x over. Full numbers,
method and three findings are in docs/evidence/perf-ft070-2026-09-13.

The clearest of those findings: typesetting a 2 MB document costs 42.7 s with
the document sources attached and 1.04 s without. Two per-formula code paths in
render-pipeline's typeset ask a question about the preamble and answer it by
searching the entire document, so a document that does not contain the searched
string pays a full scan per formula. That crate is another lane's, so this lane
has measured and reported it rather than touching it.

Gates unchanged (this adds a crate and edits no existing crate's source):
amsmath 59/59, HW1/HW2 3 pages with 0 errors and 0 overfull, render-pipeline
170 passed / 0 failed, compiler 395 passed / 0 failed, perf-bench 13 passed.

Implementation-Agent: Claude Opus 5 (FT-070 perf lane, linux-primary)
Commit-Executor: Claude Opus 5 (direct agent Git execution, per the AGENTS.md
  Cursor-limit fallback in force on this machine)
Co-authored-by: GoKubar <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
The memory work measures with this harness, so the lane branches from main
with the harness merged in rather than duplicating the crate.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…ilities fields)

`typeset::assemble` grew `page_color`/`default_color` and `v1::Capabilities`
grew `device_color`/`delta`/`v2_only` after the harness was written. Pass
`None`/`None` and spread the default so the measured path is still the one the
committed baselines were recorded against.

Reported on PR #206.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
…lyph

`Cluster` carried a `Carets { first: Caret, last: Option<Caret> }` — 72 of
its 160 bytes — and a text run emits one cluster per glyph, so a 1507-page
document held 1.48 million caret pairs. They were never independent data:

  carets.first == Caret { text_byte: text_start_byte,
                          x:  hit_rect.x,
                          top: hit_rect.top,
                          height: hit_rect.height }

at all three construction sites (text runs, math, TikZ node text), and
`place_item`/`shift_x` moved the rect and both carets by the same offset,
so placement preserved it too. Audited over the twelve corpus cases —
1 991 552 clusters — the start caret was byte-identical to the derived one
in every single one, the end caret never sat on a cluster other than its
run's last, and its top/height always equalled that cluster's hit rect.

So `Cluster` keeps the rect and derives both carets, and the one thing that
is genuinely not derivable — the end caret's `x` (the TikZ path clamps the
hit rect's width to one tick but not the caret) and its text byte — moves to
the run as `GlyphRun::end_caret`, one per run instead of 40 bytes per glyph.
`Cluster`: 160 -> 88 bytes.

This also makes an invariant structural that `join_runs` used to maintain by
hand: it cleared the joined-over cluster's trailing caret so that only a
run's last cluster carried one. With the caret on the run there is nowhere
for a mid-run one to live.

Output is unchanged and that is the point of the change: both JSON emitters
and the delta digest now call `GlyphRun::carets_of`, which reconstructs the
same `Carets` value. `delta::changed_items` compares `end_caret` once per run
in place of `carets` per cluster — the same comparison, since the rest of the
caret is the cluster bytes and hit rect it already compares.

Measured on synthetic-2mb (1507 pages, 1.48M clusters), the perf harness
reports identical digests for all three scenarios (cold.reply
b0d5e89b71ab0200, warm.type-display-eq 4ec7e38a83002099,
warm.type-paragraph 484f07ea71d1b181) and steady RSS 5107 -> 4897 MiB.

FT-070. Reported on PR #206.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
FT-070's memory gap was a single number with no attribution. This adds the
instrument, so the breakdown is measured rather than argued about.

`render_pipeline::memsize` walks an already-built display list and render
cache and charges allocated bytes (capacity, not length — that is what the
allocator holds) to named lines, counting each shared `Rc` once so the two
totals can be added. It is read-only and touches no render path.

`memprofile <case>` renders a corpus case through the product path, runs the
warm keystrokes the harness runs, and reports VmRSS, live bytes from a
counting global allocator, and the walked breakdown, so the three gaps are
separated: live-minus-walked is what the walk cannot reach (font, expander
and compiler caches), RSS-minus-live is allocator retention, and a
`malloc_trim(0)` probe splits that last one into trimmable and fragmented.

It is a second binary because the counting allocator must not be linked into
the timing binary, and `main.rs` keeps its own module declarations: every
committed baseline was recorded by it exactly as it stands.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
Two tests constructed or read `Cluster.carets` directly. The JSON
round-trip test now sets the run's `end_caret` — which also makes it check
that both writers agree about *which* cluster shows the end caret, not just
about its value — and the joined-fragment test reads `GlyphRun::carets_of`,
so it still asserts the property it was written for: a caret never falls
outside its own cluster's byte range.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 14, 2026
… and the page's items accessor

Three semantic conflicts between this lane and main's `\lVert`/`\rVert` and
extensible-delimiter work. The textual merge was clean; none of them is.

`typeset.rs`'s stacked-assembly cluster (main's extensible delimiter, one
cluster holding the whole Latin Modern Math assembly) set `Cluster.carets`
explicitly. #232 removed that field: the carets are derived from
`text_start_byte` and `hit_rect` (`Cluster::first_caret`), and the run-level
`end_caret` supplies `last` for the final cluster only. The literal it wrote --
`first { text_byte: start, x: g.x, top, height: hh }`, `last: None` -- is
exactly what the accessor derives from the `hit_rect { x: g.x, top, width,
height: hh }` it sits beside, and the run is built with `end_caret: None`, so
dropping the field is value-preserving rather than a behaviour change.

`tests/big_delimiter_packages.rs` and `tests/extensible_delimiters.rs` are new
on main and read `&page.items`, which this lane made a method returning
`Option<&Vec<Item>>`. Both are unwindowed renders, so they take
`resident_items()` -- the accessor that panics on an elided page rather than
reading it as empty -- like the other 20 tests this lane converted.

Builds: `cargo build --tests` clean in render-pipeline, flashtex-cli and
perf-bench.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary NixOS)
Commit-Executor: claude-opus-5 (direct git; Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar pushed a commit that referenced this pull request Sep 15, 2026
…ositions, new compiler lanes (#246)

The board still said "main ad71b64" with FT-050..055 as the queue. It now
carries the FT-060..067 outcomes, the two standing performance programs
(FT-070 Kabir, FT-071 Mac), the dispositions agreed on issue #2 for the
53 open PRs (Kabir's 2026-09-14T00:10Z triage), the merge order #233 ->
#241 -> #230 -> #231 -> #232, and the three unclaimed compiler lanes
#242/#243/#244 that close the last real-world corpus errors. Historical
rows are kept below.

Implementation-Agent: Claude Code (mac-claude-a)
Commit-Executor: git via Claude Code

Claude-Session: https://claude.ai/code/session_01Y1nAv4pEnmMYXgteBoadHn

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@GoKubar
GoKubar marked this pull request as ready for review September 15, 2026 15:37
typeset::assemble grew page_color/default_color (mirrored from the
product path in lib.rs, doc.page_color/doc.default_color), and
v1::Capabilities grew device_color/delta/v2_only, all off in the
harness's fixed capability set.

Implementation-Agent: fable-ft070
Commit-Executor: fable-ft070 (direct; Cursor usage limit)
# Conflicts:
#	crates/render-pipeline/src/typeset.rs
# Conflicts:
#	crates/perf-bench/src/measure.rs
The Sep 13 baseline no longer describes main: the engine moved ~465
commits (integration queues #644/#646 and today's ~66 merges), and the
digest half of the gate is a hard equality against recorded output, so
every PR was failing on drift this harness did not cause. Verified on
the Sep 14 run of #232: FAIL was 'output changed in 50 place(s)' only;
timings were correctly reported-not-enforced on the foreign runner.

Why re-recording is legitimate rather than gate-disarming:
- This branch adds no engine code (crates/perf-bench, .github, docs
  only), so the tree whose output was recorded IS origin/main's engine,
  byte for byte. The digest drift is main's own, each contributing PR
  individually gated by the pdflatex oracles.
- Same reference host as the Sep 13 recording (linux/x86_64/AMD Ryzen 7
  7800X3D/16cpu), same build profile, recorded by the same procedure
  (README), full 26-case corpus at the current cap policy.
- Old vs new, 267 metrics: 90 digests changed; timings moved with
  main's own optimization work, dominated by the adapt fix (#623):
  synthetic-500kb cold 3434.9 -> 531.5 ms, synthetic-2mb first render
  44513.5 -> 2344.2 ms, math-heavy 184.1 -> 134.5 ms. Improvements of
  that size are exactly what a stale timing baseline can no longer
  calibrate against.

The corpus grew from 12 to 26 recorded cases (article-twocolumn,
input-bibliography and the other real-world fixtures landed on main
after Sep 13); the gate's per-PR --only set is a subset. Known notes
carried in the report, not failures: tikz-heavy PDF export is refused
by the exact route (path_stroke unsupported - a product limitation the
harness reports), siunitx-tables carries an unsupported \SI syntax
diagnostic, unicode-accents reports CJK missing_glyph.

Implementation-Agent: fable-ft070
Commit-Executor: fable-ft070 (direct; Cursor usage limit)
@GoKubar

GoKubar commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Merged current main plus the updated #206 harness (this PR stacks on it). CI failures triaged and addressed:

  • rust bridge (ubuntu): real_bridge_cli_exposes_validation_without_preparing_source_edit failed with store_in_use from the spawned real CLI. That is a fork/flock inheritance race, not this PR (which does not touch bridge): the test's journal flock fd can be duplicated into a concurrently-forked child of another test and survives until its exec's O_CLOEXEC — a microsecond window that a loaded 4-cpu runner can hit. Passed on macOS then; passes locally now (18 suites, 0 failures under --locked). If it re-flakes, the fix belongs in the bridge test (retry or serialize the real-CLI spawns).
  • engine performance: failed only on stale baseline digests (output changed in 50 place(s) — main's own drift since Sep 13). The baseline is re-recorded on FT-070: engine performance harness, committed baseline and a >5% regression gate #206 and merged here.
  • merge conflicts: resolved keeping the derived-carets design and adopting main's provenance_of; main's two new Cluster construction sites (\dotfill from render-pipeline: explicit glue keeps the space factor (min-hrulefill 0.554 bp -> 0.004 bp) #548 and math assemblies) are converted to the derived pattern, wire-identical via carets_of.

Verification: full render-pipeline suite 452 passed / 0 failed with repo fonts; perf gate run in this tree against the fresh baseline: 0 digest changes over 296 metrics — direct evidence the Cluster 160→88 B work is output-neutral against current main.

One honest flag: on the reference host, tikz-heavy shows a consistent +6–11% (cold.render, typeset, warm keystrokes) versus the #206 tree, which A/B-checks clean against the same baseline — so it is this branch's cost, presumably caret derivation on the cluster-per-glyph TikZ path. Under the >5% rule this would gate on the reference host; on hosted runners it is reported, not enforced. Worth either a look at carets_of on the TikZ path or an explicit acceptance note before merge.

GoKubar added a commit that referenced this pull request Sep 15, 2026
…ession gate (#206)

* perf-bench: FT-070 benchmark harness, committed baseline and a >5% gate

There was no way to tell whether an engine change made the compiler faster.
The numbers that existed came from `examples/stages.rs` and `perf_bench.rs`:
macOS-only metadata, one sample per cell, no memory figure, no machine-readable
output, and no way to fail a build on a regression. This adds a harness whose
output can be argued with.

`crates/perf-bench` measures the product path -- the same
`protocol::handle_line` the `flashtex-render` worker serves -- over the ten
committed real-world fixtures and four generated documents (500 KB, 2 MB,
math-heavy, TikZ-heavy; generators committed, not blobs). Per case it reports
cold timings with a per-phase split, warm single-keystroke timings, PDF export,
peak and steady RSS, and an output digest. `--baseline ... --check` turns the
same run into a CI gate.

Three rules the harness enforces on itself, because breaking any of them
produces numbers that look fine and mean nothing:

* No measurement without fonts. Latin Modern and the pinned 12 pt TFM set must
  load and no render may substitute a face or a metric, or the case produces no
  timing at all -- a substituted metric is a different workload, not a slower
  one. The font set is built with `FontSet::with_dirs`, which probes nothing,
  so this box's TeX Live cannot supply the metrics by accident. The line is
  drawn at the configuration, not the document: a character with no glyph, or a
  class command the compiler does not model, is deterministic and identical
  every run, so the case is measured and the degradation is recorded next to
  the number.
* Cold means cold. Every repetition runs in a child process of its own, so the
  expander's thread-local cache, the font set's memoised faces and the
  allocator all start empty, and peak RSS belongs to one document.
* Medians, with the spread shown. Nothing comes from one sample; every metric
  carries n, p25/p75, p95 and MAD, and the table prints the run's own noise
  estimate per case.

The gate is built to survive a shared machine. A metric counts as regressed
only when it exceeds both the tolerance and that metric's own measured spread
in the baseline, and the comparison warns and stops enforcing timings when the
host, build profile, font configuration or peak load differ. Output identity
does not depend on the machine -- the fonts come from the repository -- so a
changed digest fails everywhere and unconditionally.

Baseline, at main 8465bbd on a Ryzen 7 7800X3D: cold HW1 meets its 10 ms
target; warm keystroke is 153x over budget at 500 KB and 132x at 2 MB, HW1 PDF
export is 5.6x over, and steady memory at 2 MB is 49x over. Full numbers,
method and three findings are in docs/evidence/perf-ft070-2026-09-13.

The clearest of those findings: typesetting a 2 MB document costs 42.7 s with
the document sources attached and 1.04 s without. Two per-formula code paths in
render-pipeline's typeset ask a question about the preamble and answer it by
searching the entire document, so a document that does not contain the searched
string pays a full scan per formula. That crate is another lane's, so this lane
has measured and reported it rather than touching it.

Gates unchanged (this adds a crate and edits no existing crate's source):
amsmath 59/59, HW1/HW2 3 pages with 0 errors and 0 overfull, render-pipeline
170 passed / 0 failed, compiler 395 passed / 0 failed, perf-bench 13 passed.

Implementation-Agent: Claude Opus 5 (FT-070 perf lane, linux-primary)
Commit-Executor: Claude Opus 5 (direct agent Git execution, per the AGENTS.md
  Cursor-limit fallback in force on this machine)
Co-authored-by: GoKubar <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* perf-bench: follow main's assemble and Capabilities signatures

typeset::assemble grew page_color/default_color (mirrored from the
product path in lib.rs, doc.page_color/doc.default_color), and
v1::Capabilities grew device_color/delta/v2_only, all off in the
harness's fixed capability set.

Implementation-Agent: fable-ft070
Commit-Executor: fable-ft070 (direct; Cursor usage limit)

* perf-bench: recalibrate the committed baseline to current main

The Sep 13 baseline no longer describes main: the engine moved ~465
commits (integration queues #644/#646 and today's ~66 merges), and the
digest half of the gate is a hard equality against recorded output, so
every PR was failing on drift this harness did not cause. Verified on
the Sep 14 run of #232: FAIL was 'output changed in 50 place(s)' only;
timings were correctly reported-not-enforced on the foreign runner.

Why re-recording is legitimate rather than gate-disarming:
- This branch adds no engine code (crates/perf-bench, .github, docs
  only), so the tree whose output was recorded IS origin/main's engine,
  byte for byte. The digest drift is main's own, each contributing PR
  individually gated by the pdflatex oracles.
- Same reference host as the Sep 13 recording (linux/x86_64/AMD Ryzen 7
  7800X3D/16cpu), same build profile, recorded by the same procedure
  (README), full 26-case corpus at the current cap policy.
- Old vs new, 267 metrics: 90 digests changed; timings moved with
  main's own optimization work, dominated by the adapt fix (#623):
  synthetic-500kb cold 3434.9 -> 531.5 ms, synthetic-2mb first render
  44513.5 -> 2344.2 ms, math-heavy 184.1 -> 134.5 ms. Improvements of
  that size are exactly what a stale timing baseline can no longer
  calibrate against.

The corpus grew from 12 to 26 recorded cases (article-twocolumn,
input-bibliography and the other real-world fixtures landed on main
after Sep 13); the gate's per-PR --only set is a subset. Known notes
carried in the report, not failures: tikz-heavy PDF export is refused
by the exact route (path_stroke unsupported - a product limitation the
harness reports), siunitx-tables carries an unsupported \SI syntax
diagnostic, unicode-accents reports CJK missing_glyph.

Implementation-Agent: fable-ft070
Commit-Executor: fable-ft070 (direct; Cursor usage limit)

---------

Co-authored-by: Claude Opus 5 <[email protected]>
# Conflicts:
#	crates/perf-bench/Cargo.toml
@GoKubar
GoKubar merged commit 2d1b517 into main Sep 15, 2026
11 of 22 checks passed
GoKubar added a commit that referenced this pull request Sep 15, 2026
…ntegration queue)

- protocol.rs: #651's size-first envelope refusal kept whole; this
  branch's contribution grafted in — the refusal's capability echo also
  filters -only and -window, since nothing sibling-shaped was accepted.
- memsize.rs / memprofile.rs: this branch's window-aware versions are
  supersets of the #232 versions main landed; kept ours.
- typeset.rs: comment-only (derived-carets note on the math assembly).

Implementation-Agent: fable-ft070
Commit-Executor: fable-ft070 (direct; Cursor usage limit)
GoKubar added a commit that referenced this pull request Sep 15, 2026
…ted-latex docs

Only conflict was docs/user/compiler.md (generated); resolved by
re-running crates/compiler/scripts/render_supported_latex.sh, never
hand-merged. apps/mac/scripts/sync-supported-latex.sh reports the
bundled copy current.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu
GoKubar added a commit that referenced this pull request Sep 15, 2026
GoKubar added a commit that referenced this pull request Sep 15, 2026
… has no reply (#294)

* perf-bench: FT-070 benchmark harness, committed baseline and a >5% gate

There was no way to tell whether an engine change made the compiler faster.
The numbers that existed came from `examples/stages.rs` and `perf_bench.rs`:
macOS-only metadata, one sample per cell, no memory figure, no machine-readable
output, and no way to fail a build on a regression. This adds a harness whose
output can be argued with.

`crates/perf-bench` measures the product path -- the same
`protocol::handle_line` the `flashtex-render` worker serves -- over the ten
committed real-world fixtures and four generated documents (500 KB, 2 MB,
math-heavy, TikZ-heavy; generators committed, not blobs). Per case it reports
cold timings with a per-phase split, warm single-keystroke timings, PDF export,
peak and steady RSS, and an output digest. `--baseline ... --check` turns the
same run into a CI gate.

Three rules the harness enforces on itself, because breaking any of them
produces numbers that look fine and mean nothing:

* No measurement without fonts. Latin Modern and the pinned 12 pt TFM set must
  load and no render may substitute a face or a metric, or the case produces no
  timing at all -- a substituted metric is a different workload, not a slower
  one. The font set is built with `FontSet::with_dirs`, which probes nothing,
  so this box's TeX Live cannot supply the metrics by accident. The line is
  drawn at the configuration, not the document: a character with no glyph, or a
  class command the compiler does not model, is deterministic and identical
  every run, so the case is measured and the degradation is recorded next to
  the number.
* Cold means cold. Every repetition runs in a child process of its own, so the
  expander's thread-local cache, the font set's memoised faces and the
  allocator all start empty, and peak RSS belongs to one document.
* Medians, with the spread shown. Nothing comes from one sample; every metric
  carries n, p25/p75, p95 and MAD, and the table prints the run's own noise
  estimate per case.

The gate is built to survive a shared machine. A metric counts as regressed
only when it exceeds both the tolerance and that metric's own measured spread
in the baseline, and the comparison warns and stops enforcing timings when the
host, build profile, font configuration or peak load differ. Output identity
does not depend on the machine -- the fonts come from the repository -- so a
changed digest fails everywhere and unconditionally.

Baseline, at main 8465bbd on a Ryzen 7 7800X3D: cold HW1 meets its 10 ms
target; warm keystroke is 153x over budget at 500 KB and 132x at 2 MB, HW1 PDF
export is 5.6x over, and steady memory at 2 MB is 49x over. Full numbers,
method and three findings are in docs/evidence/perf-ft070-2026-09-13.

The clearest of those findings: typesetting a 2 MB document costs 42.7 s with
the document sources attached and 1.04 s without. Two per-formula code paths in
render-pipeline's typeset ask a question about the preamble and answer it by
searching the entire document, so a document that does not contain the searched
string pays a full scan per formula. That crate is another lane's, so this lane
has measured and reported it rather than touching it.

Gates unchanged (this adds a crate and edits no existing crate's source):
amsmath 59/59, HW1/HW2 3 pages with 0 errors and 0 overfull, render-pipeline
170 passed / 0 failed, compiler 395 passed / 0 failed, perf-bench 13 passed.

Implementation-Agent: Claude Opus 5 (FT-070 perf lane, linux-primary)
Commit-Executor: Claude Opus 5 (direct agent Git execution, per the AGENTS.md
  Cursor-limit fallback in force on this machine)
Co-authored-by: GoKubar <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* perf-bench: build against current main (assemble colour params, Capabilities fields)

`typeset::assemble` grew `page_color`/`default_color` and `v1::Capabilities`
grew `device_color`/`delta`/`v2_only` after the harness was written. Pass
`None`/`None` and spread the default so the measured path is still the one the
committed baselines were recorded against.

Reported on PR #206.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* display list: derive the cluster carets instead of storing them per glyph

`Cluster` carried a `Carets { first: Caret, last: Option<Caret> }` — 72 of
its 160 bytes — and a text run emits one cluster per glyph, so a 1507-page
document held 1.48 million caret pairs. They were never independent data:

  carets.first == Caret { text_byte: text_start_byte,
                          x:  hit_rect.x,
                          top: hit_rect.top,
                          height: hit_rect.height }

at all three construction sites (text runs, math, TikZ node text), and
`place_item`/`shift_x` moved the rect and both carets by the same offset,
so placement preserved it too. Audited over the twelve corpus cases —
1 991 552 clusters — the start caret was byte-identical to the derived one
in every single one, the end caret never sat on a cluster other than its
run's last, and its top/height always equalled that cluster's hit rect.

So `Cluster` keeps the rect and derives both carets, and the one thing that
is genuinely not derivable — the end caret's `x` (the TikZ path clamps the
hit rect's width to one tick but not the caret) and its text byte — moves to
the run as `GlyphRun::end_caret`, one per run instead of 40 bytes per glyph.
`Cluster`: 160 -> 88 bytes.

This also makes an invariant structural that `join_runs` used to maintain by
hand: it cleared the joined-over cluster's trailing caret so that only a
run's last cluster carried one. With the caret on the run there is nowhere
for a mid-run one to live.

Output is unchanged and that is the point of the change: both JSON emitters
and the delta digest now call `GlyphRun::carets_of`, which reconstructs the
same `Carets` value. `delta::changed_items` compares `end_caret` once per run
in place of `carets` per cluster — the same comparison, since the rest of the
caret is the cluster bytes and hit rect it already compares.

Measured on synthetic-2mb (1507 pages, 1.48M clusters), the perf harness
reports identical digests for all three scenarios (cold.reply
b0d5e89b71ab0200, warm.type-display-eq 4ec7e38a83002099,
warm.type-paragraph 484f07ea71d1b181) and steady RSS 5107 -> 4897 MiB.

FT-070. Reported on PR #206.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* perf-bench: a memory profile that says where the resident bytes went

FT-070's memory gap was a single number with no attribution. This adds the
instrument, so the breakdown is measured rather than argued about.

`render_pipeline::memsize` walks an already-built display list and render
cache and charges allocated bytes (capacity, not length — that is what the
allocator holds) to named lines, counting each shared `Rc` once so the two
totals can be added. It is read-only and touches no render path.

`memprofile <case>` renders a corpus case through the product path, runs the
warm keystrokes the harness runs, and reports VmRSS, live bytes from a
counting global allocator, and the walked breakdown, so the three gaps are
separated: live-minus-walked is what the walk cannot reach (font, expander
and compiler caches), RSS-minus-live is allocator retention, and a
`malloc_trim(0)` probe splits that last one into trimmable and fragmented.

It is a second binary because the counting allocator must not be linked into
the timing binary, and `main.rs` keeps its own module declarations: every
committed baseline was recorded by it exactly as it stands.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* tests: build the cluster carets through the derived accessor

Two tests constructed or read `Cluster.carets` directly. The JSON
round-trip test now sets the run's `end_caret` — which also makes it check
that both writers agree about *which* cluster shows the end caret, not just
about its value — and the joined-fragment test reads `GlyphRun::carets_of`,
so it still asserts the property it was written for: a caret never falls
outside its own cluster's byte range.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* display list: materialise a bounded window of pages, not the whole document

FT-070's structural half. #232 established that 100 MB over 1507 pages is
~68 KB a page -- less than one page of glyph data at any representation that
keeps per-glyph carets and source ranges -- so the target cannot be reached by
representation and the document has to stop being resident.

`protocol/proposals/display-list-v2-window.md` is the proposal; this is its
producer-side prototype. The wire capability is specified and NOT negotiated:
`v1.rs` does not accept the name, no consumer sends it, and an unwindowed
render -- every render on every route today -- is byte-for-byte unchanged.

Where the window belongs. `-only` and `-delta` are serialisation levers: they
choose what of an already-built `DisplayList` reaches the consumer, so a
`-window` built at that boundary would cut wire bytes and leave resident memory
exactly where it is. The window therefore takes effect at `typeset::assemble`,
the first point where per-page glyph data exists, and is declared at the
protocol boundary because whether a reply covers the whole document is a
contract fact, not something a consumer should infer.

Layout still runs over the whole document -- page breaking, `\pageref`, floats
and contents lists are global and a window over them would change output. Only
assembly is windowed.

The completeness hazard, and what it forced. The font closure and the
`math_resource_profile` / `math_glyph_unmapped` diagnostics are derived during
assembly over every block, so a window that assembled only its own blocks would
emit a quietly smaller closure and fewer diagnostics. `assemble_windowed`
therefore still visits every block in the same order and harvests before it
drops: what the window changes is retention, not the traversal. An assembled
block reaching no resident page is dropped and never cached.

`Page.items: Vec<Item>` becomes `Page.content: PageContent` (`Resident(..)` or
`Elided`). Deliberately a breaking change rather than a `resident: bool` beside
a retained `items`: the failure mode being designed against is a consumer that
reads `items` without checking, and there is now no silent path. `pdf::write_pdf`
refuses a windowed list, `v1::fallback` skips an elided page, and `delta` takes
no snapshot from one and emits no delta against one (a window and a delta are
mutually exclusive in r1, since the delta's `list_digest` binds a digest for
every page).

On the wire an elided page carries its frame, `"resident": false` and no
`items` key at all -- absent, not `[]`, so a consumer that ignored the flag
fails to decode rather than painting a blank page. A resident page gains no
marker, which is what keeps every existing digest identical.

`tests/page_window.rs` is the acceptance gate, and it is equality rather than a
digest: over every window position of a 20-page document, each resident page
must serialise byte-identically to that page in the unwindowed render, and the
documents, fonts, diagnostics and required features must match the complete
compile's. A digest would only prove a consumer rebuilt what it was sent; the
risk here is a producer sending a correct-looking smaller closure.

Measured with `memprofile --window 1:16` against an unwindowed control on the
same code path (`--render-only`), 2 MB / 1507 pages: live 1440.7 -> 920.0 MiB,
VmRSS 2912.3 -> 2035.8, display list 247.5 -> 2.5. 500 KB / 385 pages: live
363.2 -> 238.1, VmRSS 748.8 -> 541.9. The display list stops scaling with the
document, which is the property this is for. What remains is
`RenderCache.blocks`, whole-document by design because it is what makes
re-materialising a page cheap -- and 2036 MiB is still 20x the 100 MB target.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary NixOS)
Commit-Executor: claude-opus-5 (direct git; Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* display list: scope the assembled cache to the window, so a scroll stays bounded

Without this the window is only a first-render win. `RenderCache.assembled` is
append-only -- its sole bound is "clear everything at 50 000 entries" -- so a
viewer scrolling a long document accumulates the glyph-level assembly of every
page it has passed, and the resident set climbs back to the whole document
while the window keeps claiming to be 16 pages.

A windowed render now ends by retaining exactly the blocks its resident pages
used. `blocks` and `adapted` are deliberately untouched: they are the
whole-document layout records that make re-materialising a page cheap, and they
are the cache lines the measurements show remaining (160.2 MiB of
`BuiltBlock.items` and 73.1 MiB of `ClusterRec` at 2 MB). Bounding those is
#232's follow-up 3, not this.

An unwindowed render never calls `retain_assembled`, and now also treats every
block as wanted whether or not a page placed it -- so a complete compile's cache
behaviour is byte-for-byte and entry-for-entry what it was before the window
existed, rather than merely equivalent in output.

Also: `flashtex-cli`'s `has_content` reads through `Page::items()`, and the
proposal now states per section what r1 implements against what it specifies.
The gap worth naming is §5.5: the page recipe is NOT retained across requests,
so r1 re-runs layout for every window. Serving a scroll without re-layout is
the point of retaining it and is r2; the memory this change measures does not
depend on it, which is why it is separated rather than bundled in unmeasured.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary NixOS)
Commit-Executor: claude-opus-5 (direct git; Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* display list: size the page window by the reply limit, not by a memory budget

The window lane was written against FT-070's 100 MB target. PR #273 measured
something more urgent with the same cause: a 500 KB document has **no reply at
all** today. Its `display_list` sibling would be 164 MB against a 16 MiB line
limit, so `handle_line` declines it without serialising; the v1 `compile_result`
that would carry the pages instead is 20 339 909 bytes for those 385 pages, also
over; the request ends `status: failed`.

Neither existing sibling capability fixes that, and the reasons are structural.
`-delta` needs the full `DisplayList` from `render_cached` before it can diff
anything, so it shrinks the wire after the producer has already built and failed
to fit the whole document. `-only` empties the v1 `pages` only when a sibling is
present, and here the sibling is the 164 MB line that was declined. The window is
the only one of the three that makes the producer build less, which is what a
size limit actually requires.

So `MAX_WINDOW_PAGES` was 512, which is indefensible: at the measured ~426 KB a
page that is 218 MB. It is now 64, derived from the arithmetic -- a 16 MiB line
carries ~39 pages of that document and the runtime's 8 MiB framed default ~19,
both more than a viewer shows and both finite where 1507 pages is not.

`PageWindow::fitting(centre, pages, bytes_per_page, limit)` is the widest window
a given limit can carry. It takes a measured `bytes_per_page` rather than a
constant, because page size varies by an order of magnitude between a title page
and a dense one and a constant here would be a guess presented as a bound; the
caller supplies the previous reply's `page_bytes` or its own estimate. A page too
large for even one to fit still yields a one-page window -- refusing is the
protocol's job, not the window's. Nothing calls it until the capability is
negotiated.

The consequence worth recording is a composition result: `-window` and `-only`
are each useless alone at this scale and sufficient together. The v1 payload
fails on its own at 385 pages (20.3 MB) and the v2 sibling fails on its own
(164 MB), so a consumer that wants large documents to work sends
`display-list-v2`, `-only` and `-window` together. That is the first hard reason
in this protocol to require two capabilities rather than choose between them.

Proposal gains §1.0 for the failure, §1.1 for the memory argument it started
from, and the §7 composition rule. `tests/page_window.rs` gains
`a_window_is_sized_by_the_reply_limit`, which pins the arithmetic against #273's
measured page size rather than against a number invented here.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary NixOS)
Commit-Executor: claude-opus-5 (direct git; Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* merge main: the new extensible delimiters build on the derived carets and the page's items accessor

Three semantic conflicts between this lane and main's `\lVert`/`\rVert` and
extensible-delimiter work. The textual merge was clean; none of them is.

`typeset.rs`'s stacked-assembly cluster (main's extensible delimiter, one
cluster holding the whole Latin Modern Math assembly) set `Cluster.carets`
explicitly. #232 removed that field: the carets are derived from
`text_start_byte` and `hit_rect` (`Cluster::first_caret`), and the run-level
`end_caret` supplies `last` for the final cluster only. The literal it wrote --
`first { text_byte: start, x: g.x, top, height: hh }`, `last: None` -- is
exactly what the accessor derives from the `hit_rect { x: g.x, top, width,
height: hh }` it sits beside, and the run is built with `end_caret: None`, so
dropping the field is value-preserving rather than a behaviour change.

`tests/big_delimiter_packages.rs` and `tests/extensible_delimiters.rs` are new
on main and read `&page.items`, which this lane made a method returning
`Option<&Vec<Item>>`. Both are unwindowed renders, so they take
`resident_items()` -- the accessor that panics on an elided page rather than
reading it as empty -- like the other 20 tests this lane converted.

Builds: `cargo build --tests` clean in render-pipeline, flashtex-cli and
perf-bench.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary NixOS)
Commit-Executor: claude-opus-5 (direct git; Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* display list: negotiate the page window, so the 500 KB document has a reply

r1 specified the wire capability and deliberately did not negotiate it, because
one of the closures §3 requires whole was not yet whole. This closes that gap
and turns the name on, which is what makes the lane's product claim testable
rather than argued: the document that returns `status: failed` today now
returns a painted window.

The gap. `required_features` is derived by classifying items, and it was
derived from `resident_page_items()` -- the window's items, not the document's.
A document whose only rule sits on page 300 would have announced no `rule` to a
consumer windowed on page 1, which is the same failure as a smaller font
closure: a consumer negotiating a feature set it cannot paint the rest of the
document with. §5.6 already named the rule ("computed during the streaming
pass, over every block, not over `pages`"); r1 had not implemented it, and
`display.rs` said so in a comment. `assemble_windowed` now harvests
`DocumentFeatures` in the same pass that harvests the faces and the
diagnostics, from every block including the ones whose only pages are elided,
plus the page-level items the block loop cannot see (float images, the
`\pagecolor` rule, the document default colour). An unwindowed list still
*scans* its own items, so every line on the wire today is byte-for-byte what it
was; only a windowed list reads the harvest.

`status` too. `v1::fallback` derived `has_content` from the pages it built, and
a windowed payload holds only the resident ones, so a window over blank pages
of a document carrying an error could have reported `failed` where the
unwindowed reply says `recovered`. §4.1 says the window does not change
`status`, so the question is now asked of the same whole-document harvest.

Negotiation follows `-only`'s pattern exactly. `CAP_WINDOW` is accepted only
next to `display-list-v2`, `payload.display_list_window` says where the viewer
is, and the name is echoed only on a reply that actually carries a window --
the way `-only` is echoed only when the pages were really elided. Per §7 the
window declines `-delta`: a delta binds a digest for every page and a windowed
producer has none for a page it never materialised. Per §8 a degenerate window
is not an error; the reply is unwindowed and the echo omits the name.

One behaviour beyond r1, and it is the one that makes the capability worth
having: a window the reply limit still cannot carry is narrowed and served
rather than declined. `MAX_WINDOW_PAGES` bounds what a viewer shows, not bytes,
so a consumer can legitimately ask for 64 pages of a document whose pages are
426 KB each. Declining that is the `status: failed` this exists to fix, so the
producer measures the pages it just built, re-derives the window through the
already-present `PageWindow::fitting`, and serves that; the echoed `window` is
the authority on what was served, so the narrowing needs no diagnostic (§8).

Measured, against the real `synthetic-500kb` corpus case, 385 pages, through
the actual `flashtex-render` worker over JSON Lines:

  today's consumer   status failed -- "compile_result would be 20 339 674 bytes
                     for 385 pages, over the 16 777 216-byte reply limit"
  window 1:16        status recovered, 2 lines, sibling 5 937 794 B,
                     385 pages / 16 resident / 369 elided
  window 300:16      status recovered, sibling 6 369 270 B
  window 1:64        narrowed to 13:40 and served, 15 211 146 B

and the §9 equality gate applied to that document rather than to a 20-page
stand-in: for windows at 1, 185, 300 and 378, every resident page object is
byte-identical to that page in the unwindowed 152 MB render, all 385 page
frames match, and `documents`, `fonts`, `diagnostics` and `required_features`
are byte-identical. Zero font-failure diagnostics in every run.

Tests. `cli_e2e` gains the product bug itself as a regression test: the same
three refusals reproduced through `FLASHTEX_MAX_REPLY_BYTES` (the failure is a
ratio, not an absolute size), with the limit derived from a measured window and
the whole-document size read back out of the producer's own refusal, so nothing
is hard-coded to a page size. `page_window` gains the closure test: a document
whose only rule is on a late page, windowed on page 1, must still announce
`rule` -- and it asserts the resident page carries no rule, so the feature can
only have come from the harvest. Reverting the harvest turns that test red with
`["glyph_run", "rgba-srgb", "cluster-actualtext"]` against
`["glyph_run", "rule", "rgba-srgb", "cluster-actualtext"]`, which is the point.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary NixOS)
Commit-Executor: claude-opus-5 (direct git; Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* memprofile: build a request the worker accepts, and measure the window on the protocol path

`memprofile`'s `request()` built a JSON-RPC 2.0 envelope -- `jsonrpc`, `method`,
`params` -- and `protocol::handle_line` requires runtime-v1's
`protocol_version` / `type` / `payload`. Every warm keystroke on the default
(protocol) path was therefore answered `missing_protocol_version` and rendered
nothing, so a default run's warm phase was measuring an empty cache rather than
a populated one.

The window's published numbers are unaffected: they were measured
`--render-only` on both sides, which never builds a request. `crates/perf-bench`
proper builds a correct request (`measure.rs:204`), so the digests and the
timing gates are unaffected too. What was wrong was memprofile's own default
mode, and only its warm phase.

With that fixed, `--window` no longer has to imply `--render-only`: the
capability is negotiated, so a windowed run can drive the same protocol path
the product does, `display_list_window` and all. The comparison rule is
unchanged and now stated as "compare like with like" rather than "windowed
means render-only".

Measured at this commit, release, this machine, zero font diagnostics:

  synthetic-2mb, --render-only    VmRSS 2912.6 -> 2035.9   live 1440.8 -> 920.1
  synthetic-2mb, protocol         VmRSS 2889.0 -> 2048.5   live 1440.8 -> 920.1
  synthetic-500kb, protocol       VmRSS  751.3 ->  540.3   live  363.3 -> 238.2

The `--render-only` pair reproduces the r1 table (2912.3 -> 2035.8, 1440.7 ->
920.0) to within 0.1 MiB after the rebase onto current main and the
negotiation, which is the point of re-running it. The display list is 2.5 MiB
at 385 pages and at 1507, unchanged.

The proposal goes to r2: the capability is negotiated, `required_features` is
whole-document, `status` is window-independent, and an over-limit window is
narrowed and served rather than declined.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary NixOS)
Commit-Executor: claude-opus-5 (direct git; Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* proposal: r2 records what the producer now does, and what a consumer still has to sign

The §9 gate list gains the two tests r2 adds and the equality run against the
real 500 KB case rather than a 20-page stand-in. §1.0 gains the measured
replies -- the failure and the four windows -- so the section that argues the
bug also shows the fix. The measured table notes that the r1 numbers reproduce
after the rebase, adds the protocol-path pair the harness fix made measurable,
and records the harness fix itself rather than quietly benefiting from it.

The co-signer table gains a column. The producer row is signed; the three
consumer rows and the Commander row are unchanged in substance but are now
explicitly gating the *consumer*, because that is what negotiation changes:
no reply on any route is windowed today, and `apps/mac` must not add the name
to its capability list until the pane paints an elided page as a placeholder
rather than as nothing.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary NixOS)
Commit-Executor: claude-opus-5 (direct git; Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* protocol: a failed reply echoes no sibling capability

`-only` and `-window` are echoed only on a reply that actually carries a
sibling line. The over-limit `compile_result` path filtered `display-list-v2`
out of the echo but left those two in, so a reply that sent nothing could still
have claimed the pages were elided for a sibling, or that a window was served.
Reachable only when a windowed or `-only` v1 payload is itself over the limit,
which is why it went unnoticed; wrong either way.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary NixOS)
Commit-Executor: claude-opus-5 (direct git; Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* display list: the comments that said required_features was still the window's

Two stale notes left over from r1. `resident_page_items` said deriving a
document-wide feature set from it was unreconciled r2 work and the reason the
capability was producer-internal; the harvest reconciled it, and the doc now
says what the accessor is for instead -- what a list carries, never what the
document needs. `negotiate`'s note said "in r1" about the -window/-delta
exclusion, which outlived r1.

Comments only. The binaries used for the digest and memory runs at this SHA
predate these two edits and are unaffected by them.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary NixOS)
Commit-Executor: claude-opus-5 (direct git; Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* typeset: say which direction the feature harvest can err in

The harvest visits every block, including one placed on no page, so it can
announce a feature nothing paints. That is the safe direction -- a consumer
told to support `rule` when no rule is drawn loses nothing, while a consumer
not told is the failure the harvest exists to prevent -- and the §9 equality
gate pins the harvest against the unwindowed scan for every document it
covers, so an over-announcement surfaces as a windowed reply differing from
the unwindowed one rather than passing quietly. Worth saying where the next
reader will be standing when a gate fails.

Comment only.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary NixOS)
Commit-Executor: claude-opus-5 (direct git; Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* merge main: the new footnote and float-note oracles read the page through the accessor

`tests/footnotes_oracle.rs` and `tests/float_notes_oracle.rs` arrived on main
with the single page builder (#343) and read `&page.items`, which this lane
made a method returning `Option<&Vec<Item>>`. Both are unwindowed renders, so
they take `resident_items()` -- the accessor that panics on an elided page
rather than reading it as empty -- like the other 23 tests this lane converted.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary NixOS)
Commit-Executor: claude-opus-5 (direct git; Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* proposal: the r2 numbers, measured rather than described

The memory table stays r1's and now says so, with the r2 re-run of the 2 MB
pair beside it: 2919.5 -> 2037.0 MiB VmRSS and 1442.9 -> 922.2 live against
r1's 2912.3 -> 2035.8 and 1440.7 -> 920.0, with the display-list and
render-cache rows identical to the digit. Reproducing the control after two
merges of main is the point of re-running it.

The digest gate gets its result: 190 digests over 26 cases, 0 differing,
against a control built and run in the same directory from the same merge of
main with this lane's changes reverted.

Implementation-Agent: claude-opus-5 (engine lane, linux-primary NixOS)
Commit-Executor: claude-opus-5 (direct git; Cursor usage limit in effect)
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Xd5Hmwh5GHNTiAmHUJ1MZu

* perf-bench: the negotiated window capability stays off in the harness

Capabilities gained `window` on this branch; the harness's fixed set
keeps it off — the timing and digest gates measure the unwindowed
product path, which this branch keeps byte-identical.

Implementation-Agent: fable-ft070
Commit-Executor: fable-ft070 (direct; Cursor usage limit)

---------

Co-authored-by: Claude Opus 5 <[email protected]>
@GoKubar
GoKubar deleted the agent/linux-primary/ft070-memory branch September 16, 2026 04:17
d-q222 added a commit that referenced this pull request Sep 16, 2026
…line/perf-4-compact

What changed: resolved merge conflicts between this branch's
display-list-v2-compact encoding and main's independently-landed changes
since this branch opened.

- Wire/Capabilities: main added `diagnostics`/`window` fields alongside this
  branch's `compact`; kept all of them (display.rs, v1.rs, protocol.rs,
  delta.rs, flashtex-render.rs bin). estimated_json_bytes_for (main) and
  estimated_json_bytes_wire (this branch) were the same rename in two
  directions; standardised on estimated_json_bytes_wire (matches the
  existing to_json_wire/write_json_wire/required_features_wire naming) and
  fixed main's own unit tests and callers to match.
- PR #232 (FT-070, already on main) removed Cluster's stored `carets` field
  in favor of deriving them on demand (GlyphRun::carets_of, from hit_rect +
  a new single GlyphRun::end_caret) -- this is a genuine silent-duplicate
  trap: display_list_compact.rs (all-new in this branch) was written against
  the old stored-carets shape and did not conflict textually (main never
  touched this file), so it silently failed to compile. Adapted it to the
  derived model:
  - end_caret(r) reads r.end_caret directly instead of the last cluster's
    stored second caret.
  - The "c" per-cluster caret override is dropped entirely: since #232
    carets are always exactly derived from hit_rect + text_start_byte (plus
    the run's single end_caret on its last cluster, measured with zero
    exceptions over 2M corpus clusters), the writer's own h/hv hit-rect
    override already guarantees the decoder's derived caret matches the
    model's -- there is no longer a value carets could diverge to override.
  - read_clusters/read_full_clusters now return (Vec<Cluster>, Option<EndCaret>)
    so read_runs can populate GlyphRun.end_caret (full-encoding runs carry it
    implicitly as the last cluster's second wire caret entry).
  - tests/display_list_compact.rs: dropped the two adversarial-caret cases
    that are no longer representable (an off-hit-rect first caret; a second
    caret on a non-last cluster) and moved the "run-end caret x the hit rect
    can't derive" case (the TikZ scenario #232 itself names) onto
    GlyphRun.end_caret; updated DisplayList/Page/GlyphRun literals for
    main's window/end_caret fields; st.c (override count) 1 -> 0.
  - Swift side: RenderingV2/RenderingV2Fast/DisplayListDelta/ShellModel
    conflicts were mechanical (both branches added independent
    fields/capabilities: compact vs. diagnostics/navigation/window/delta
    exclusivity) -- combined all of them.

What was run (CARGO_TARGET_DIR=/Users/dqi26/flashtex/target-conf-257,
CARGO_BUILD_JOBS=4):
- cargo test --no-run --release (crates/render-pipeline, crates/flashtex-cli):
  compiles clean.
- cargo test --release --no-fail-fast, full crates/render-pipeline suite:
  every `test result:` line reports 0 failed (no non-"0 failed" line in the
  run's output).
- cargo test --release --test display_list_compact: 4 passed; 0 failed; 0
  ignored -- including the real-fixture corpus round trip and the 60-edit
  delta sequence.
- cargo test --release --no-fail-fast, crates/flashtex-cli: 32 passed; 0
  failed (unit) + 26 passed; 0 failed; 1 ignored (cli.rs).
- swift build --target FlashTeXProtocol and --target FlashTeXMac: both
  build clean (pre-existing unrelated warnings only).
- swift build --build-tests / swift test --filter FlashTeXProtocolTests:
  blocked by a pre-existing compile error in
  Tests/FlashTeXMacTests/PreviewV2Tests.swift ("use of local variable
  'model' before its declaration") that is byte-identical on origin/main
  (unrelated to this PR, not touched by this merge) -- could not get an
  isolated Swift test run because of it.

Next step: push and comment on PR #257 with these results; flag the
PreviewV2Tests.swift compile break to the Commander separately, since it
blocks any Swift test run on this toolchain, not just this PR's.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
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.

2 participants