Skip to content

Show a page of large text documents at once, with every tab's text in Find's reach - #5314

Merged
max-sixty merged 5 commits into
mainfrom
grind/find-plain-rows
Nov 4, 2026
Merged

max-sixty merged 5 commits into
mainfrom
grind/find-plain-rows

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

A page of large text documents now shows the open one at once, and every document's text, a closed tab's included, stays in the page for the browser's Find. lf-text-document holds each document as plain rows, one a line, and paints syntax colour only on the runs of lines the browser draws and their neighbours, as CSS custom highlights rather than spans. This builds the option chosen for "Must browser Find reach text in tabs nobody has opened?": keep Find reaching every tab, with plain rows.

Before and after

The page is #4781's repro, exported: an lf-tabs list="side" of 30 tabs, each an lf-text-document bound to its own source, with a word at the top and foot of each source for Find. all holds 4 MB a source in lines of 300–600 words; short holds the same 4 MB in lines of about 80 characters, 1.5 million lines in all; md holds 400 KB a source of 80-character Markdown with language="markdown", so the colouring is measured too. Main's exports (40e8104) beside this branch's at its head, the arms alternated on the same host, whose one-minute load stood at 20–45 for this final run and up to 100 in earlier ones from other sessions, so compare within a row.

  • Open document shows: the first animation frame in which the open tab's listing holds its text and is visible.
  • All drawn: the first frame in which all 30 listings are built.
  • Longest frame gap: the longest the main thread went without a frame between navigation and the last listing.
  • Peak RSS: the largest resident size of any process the measuring script's own browser ran (its renderer or content process).
Page Engine Open document shows All drawn Longest frame gap Peak RSS
all Chromium 156 4.55 s → 0.56 s 4.55 s → 1.01 s 4.03 s → 0.23 s 2.69 → 1.20 GB
short Chromium 156 22.9 s → 0.67 s 22.9 s → 3.04 s 22.4 s → 0.27 s 8.59 → 2.16 GB
md Chromium 156 3.01 s → 0.35 s 3.01 s → 0.64 s 2.83 s → 0.11 s 1.83 → 0.48 GB
all Firefox 157 25.0 s → 0.85 s 25.0 s → 3.31 s 24.2 s → 0.34 s 9.92 → 2.49 GB
md Firefox 157 15.2 s → 0.52 s 15.2 s → 2.75 s 14.9 s → 0.33 s 7.92 → 1.65 GB
short Firefox 157 217 s → 1.64 s 217 s → 24.4 s 216 s → 3.15 s 17.3 → 13.2 GB

Firefox short is from an earlier round of this branch, before the review's fixes, which change nothing on a page with no language; main took 3.6 minutes to show its open document there. Chromium is Playwright's headless shell 156.0.8078.4; Firefox is Playwright's build 1555.

On main the page draws nothing between the side list and the moment every document is built, so the open document waits on all 30. Here the document the page shows draws in the first task, and each hidden one takes a task of its own after it, so the page paints between them and stays answerable while the closed tabs fill in. Reloading on the 30th tab of short, which tab memory restores, shows its document at 0.64 s in Chromium and 2.44 s in Firefox, where drawn in page order it took 2.8 s and 33.4 s.

Find. In Firefox 157, window.find reaches a word only the last, unopened tab's document holds, selects it there, and opens that tab, on this branch as on main. Chromium's window.find searches no hidden="until-found" content on either arm, so there the new test asserts the word stands in the closed tab's listing; its find bar wasn't driven.

A jump far down a long document. On one 4 MB Python document (757 runs), End scrolls the last run into view, and it is coloured two frames later (40 ms in Chromium, 66 ms in Firefox), painted from a fresh grammar state; main colours it in its first frame. It is painted again with its exact state once the runs before it have been tokenized, a slice at a time. After End, Chromium drew no frame over 51 ms on that document or on a 2 MB one that opens with a long docstring. In Firefox the colouring no longer holds a frame: each token colour's ::highlight() rule was inserted into a sheet the first time it appeared, and Firefox restyled the whole page for each, 0.85 s a rule, so End's scroll appeared 1.5–1.9 s after the press. The rules are now declared in the stylesheet. Firefox still drew one frame of 0.40–0.49 s after End on both documents (two runs each, a browser warmed by an earlier load of the page); an uncoloured document does the same, so it is below under the follow-ups.

Growth. leaf-dev scaling document --base (a new axis: one ask and a text document of 64·n lines of Python, n = 8–256, so up to 16,384 lines; Chromium main-thread CPU, against ecf4dc1): main's load went 262 → 1,018 ms and a click on the ask 28 → 99 ms, an exponent of 0.88, above the 0.5 an input is held to; here load goes 213 → 283 ms (exponent 1.25, under the 1.5 for superlinear), a click 26 → 33 ms (too little growth to fit) and a wheel step 3.3 → 4.9 ms. The axis joins the daily test_scaling.py. leaf-dev scaling failed on every axis on current main (no median for empty data): since #5287 a page loads more than 250 modules, which fill resource timing's buffer before the /api/event answers it reads, so the tab now raises the buffer before loading the page; the daily test shares that measure.

Calls for you

These are what the change costs a reader, each kept on purpose:

  • Comments in a text document stand upright. ::highlight() carries only properties that don't change layout, so a token keeps its colour but not its font style: a comment or docstring, italic in main's text documents, is upright here, while lf-code and diffs keep their italic. notes/browser-support.md, "Font style in syntax highlights", records it. Still pairs (main | branch), Chromium light, dark, and Firefox: ~/.tmp/leaf.agent-a6a4236750c25a2da/long-source-selected.png, long-source-selected-dark.png, long-source-selected-firefox.png; each pair differs only there.
  • A far jump is coloured two frames late, and may read wrong at first. As above: the run shows plain for two frames, then from a fresh state, so a construct open across its first line, such as a docstring, reads wrong until its exact state arrives.
  • A printed long document colours only the runs that were near the screen. Chromium prints highlights (checked in a PDF), but runs never near the view were never tokenized. A document of 128 lines or fewer is one run and prints coloured, as before.
  • The render gate's contrast check doesn't see document tokens. unread-syntax reads token spans, and a text document has none; the same palette is still checked wherever code blocks or lf-code stand.

What changed in the widget's contract

  • Rows. listing builds a pre > code of runs of 128 rows; a row is a div holding one line's text and its ending, exactly as the source has them, so the listing's text is the source. Pierre no longer renders documents: no gutter cells, data-line* attributes or token spans, and no Pierre sheet, so listingSheet, scopedSheet and Load pages of many text documents in Firefox without restyling the page per document #5226's shared-sheet adoption go. pierre.js and the Pierre bundle stay for lf-diff.
  • Numbers. A row's number is ::before generated content, a CSS counter each run starts on its first row from --lf-lines-before, with empty alt text, so selection, copy and screen readers never take it. A counter started on the run's own box didn't reach its rows: a skipped run's style containment scoped it, and every run after the first numbered from 1. The first stills showed it, and test_a_text_document_update_keeps_a_selection_it_carries_into_another_run now reads the drawn numbers off Chromium's layout tree; it fails with the count on the run's box. A folded panel's rows (hidden="until-found") count nothing until it opens: Firefox styles and builds the generated content of rows it doesn't draw, about 120 of the 150 ms a folded 70,000-line document cost it.
  • Colour. RunColours tokenizes the runs the browser draws (contentvisibilityautostatechange, or at once for a lone run) and the run on either side of each, while the listing has a box, and paints each token as a StaticRange in one Highlight per token colour, named by the theme's colour variable (lf-token-syn-keyword and so on). text-document.css declares the ::highlight() rule for each, and tests/runtime/text-document-colours.test.mjs holds that list to the token theme's, so painting never adds a rule. A run that leaves that set drops its ranges; each highlight it touches is rebuilt from the ranges it keeps, since Firefox finds a range to delete by walking the highlight's list, and deleting two runs' ranges one by one took over 100 ms of a frame. Firefox reports a closed tab's runs drawn, and coloured every document in a closed tab as the page loaded, so a listing with no box takes no colour. Painted only as it was drawn, a run scrolling into view showed one uncoloured frame in Firefox; with its neighbours painted, a wheel scroll through a document showed none in either engine. A run starts from the grammar state the run before it ended in, so a run beginning inside a docstring or a fenced block is coloured as the whole text is; a run whose state isn't known yet is painted from a fresh state and repainted once walk finds it. A new text keeps the paint and states before its first changed line. Tokens come from the highlighter the page's code blocks and lf-code share, so a Markdown fence's language is coloured where another block on the page has loaded its grammar, as in lf-code; main's text documents left fences flat. syntax(source, lang, state) in the portable API now resolves to {tokens, state} and continues from a state it's given (module-reading.md); lf-code, the page's code blocks and test_render_anchors.py take .tokens.
  • First draw. A document the page shows draws without waiting; a hidden one first draws in a task of its own. The runs are first sized by the listing's size observer rather than in the draw: read in each draw, every closed tab's listing was a read of the page's layout, which Chromium answered more slowly for each document already drawn, 0.8 s over the 30 documents of short.
  • Kept as they were. Runs and content-visibility: auto, sizeRuns and its forgetting, reconcileRuns and the selection it carries across runs, the runtime's drawForLanding/skippableBox (untouched), the bounded viewport, holdSource and cut, the previews, and the datum marks comments anchor to.

Line numbers, selection, the selected text and copy read the same as on main in light and dark, in Chromium and Firefox: leaf-dev stills on captured-source and a new state, long-source-selected, which selects across the edge of two runs in the PR walkthrough's Rust capture. A selection across rows reads exactly the source's characters on both arms in both engines. A comment on a line deep in a long document stands its pin at the same offset from its line on both arms in both engines, moves with a scroll of the listing, and hides once the line scrolls out of it; the comment-follows-its-lines test (#5223) passes in both. An independent review confirmed these, t travel and a live data update in both engines and schemes.

Checks run

  • On the head: pnpm run test:runtime (778 pass, the new colour-rule test among them, which fails with a rule renamed), pnpm run check:browser, pnpm run test:browser, pre-commit on the changed files; uv run pytest on test_render_anchors.py, test_code_and_documents.py, test_projected_data.py, test_targets.py, test_code_review.py, test_render_export.py, test_render_gate.py and test_render_code_reading.py -k "shell or syntax or document or find or captured_source or long_quote_of_replaced or source_replacement_preserves or keeps_comments_on_their_lines or interactive_export or language or colo or highlight or token or lf_code or excerpt or code_line" (51 pass, Chromium and Firefox where parametrized, test_shell_commands_share_colors_in_plain_code_widgets_and_diffs among them); and, before this last change, the two thread tests that read message code colour.
  • test_find_reaches_the_text_of_a_document_in_a_tab_nobody_opened now asserts the opened document's lines carry lf-token-* ranges and the unopened one's carry none; with RunColours.follow a no-op it fails in both engines.
  • Earlier, before the merges: the bounds, focus-ring and interactive-export tests that hold text documents. test_code_wrapping_keeps_source_copy_and_reader_choice failed the same way on main then (a tap on the shortcut list's Copy code timed out).
  • The measuring scripts (build.py, build_code.py, frames.py, memory.py, endframes.py, lasttab.py, find_test.py, ffinval.py) and probes stay in the worktree's .tmp/perf/ and .tmp/js/.

Not verified

  • Printing in Firefox and WebKit: only Chromium's PDF was read.
  • Chromium's find bar on a closed tab: window.find there searches no fold.
  • WebKit: the Highlight API check ran in Playwright's WebKit 27.2 (colour, StaticRange, shadow root), but no text-document test or still did.
  • The daily test_scaling.py with the new document axis and the buffer fix was not run as the daily suite runs it, only leaf-dev scaling document --base and leaf-dev scaling asks --sizes 32.
  • In Chromium, a document whose tab the reader closes keeps the colour of the runs it last drew, since Chromium reports neither a skipped run nor a size for a closed tab's listing; a handful of runs per document opened.

Found along the way, not changed here

  • Firefox restyles the whole page on an insertion near its top. Appending a <p> to main on the all page costs Firefox 157 a 2.6 s style flush on main and about 0.27 s here, and 6–16 s on short; Chromium takes 7 ms. A rule-by-rule bisect of the page's stylesheets found no single rule behind more than 15% of it. A Gecko profile of short's load spent most of its time in style flushes that the runtime's visibility reads force (skipped in shown-box.js, from a frame callback and a mutation observer), which I take to be this restyle, not shown; any interaction that inserts near the top of a large page would pay it too.
  • Two runtime passes walk every element a widget draws. On short in Chromium, keyboard-scope marking (markScopedIn, keyboard/scopes.js) took about 1.0 s and the watchArrivals("*") owner watch (arrivals.js) about 0.8 s of the 3.2 s of main-thread CPU, walking 1.5 million rows that hold no scope and no owner.
  • Firefox restyles every row once, about half a second on 4 MB. On the 4 MB Python document and the 2 MB docstring one, a Firefox profile shows two style passes of 194,538 elements each (every row and its number), with no selector matching, so a recascade from above. In a browser warmed by an earlier load one lands after End (0.40–0.49 s); in a freshly launched one, two land about 6 s after load with no input at all (0.39–0.64 s each), at the moment sizeRuns resizes every run as the face arrives. An uncoloured document does the same; main's builds of these documents draw no frame over about 115 ms. Not the cause, each tried: the inherited --lf-lines-before on every run (made non-inherited), sizeRuns' forgetting step (turned off), the numbers' absolute positioning (floated) and one counter name for every run. Adding any stylesheet to the page after load pays the pass early, so something leaves the whole listing's style dirty; finding what is a follow-up.
  • Firefox's peak on short is 13 GB. Taking the closed tabs' listings out of rendering (display: none) left it at 13.1 GB, so their frames aren't the cause. The review's control: the same 1.5 million rows built by a bare script take 2.4 GB in Firefox, so most of the 13 GB is Leaf's own work per row.
  • Pierre now serves only lf-diff; its bundle and pierre.js could move from the default package to the diff package.

Part of #4781: the open document no longer waits on every source, which is what the issue reports; the issue stays open for the follow-ups above until they have issues of their own.

This was written by Claude Code on behalf of max-sixty

max-sixty and others added 3 commits November 3, 2026 23:43
… Find's reach

lf-text-document holds each document as plain rows, one a line, in runs the browser
draws only in view, and paints syntax colour as CSS custom highlights on the runs it
draws and their neighbours. Pierre no longer renders documents: no token spans, gutter
cells or per-document sheet. Line numbers are a counter in generated content, started
on each run's first row, since a skipped run's style containment scopes a count started
on its own box. Each run is tokenized from the grammar state the run before it ended in,
which the syntax module now returns and `syntax(source, lang, state)` takes
(`syntaxState`). Each document's first draw takes a task of its own, and the size
observer, not the draw, first sizes the runs.

On #4781's 30 x 4 MB export, the open document shows in 0.6 s instead of 4.3 s
(Chromium, long lines), 0.7 s instead of 26-30 s (80-character lines) and 0.9 s
instead of 28 s (Firefox, long lines), at a fraction of the memory. Comments in a text
document lose their italic, which a highlight can't carry.

leaf-dev scaling gains a `document` axis and reads its event answers past the resource
timing buffer, which the runtime's modules have filled since #5287.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	packages/default/widgets/lf-text-document.js
…ces flat

A run far down a long text document is painted at once from a fresh grammar state and
painted again once a walk through the runs before it, a slice at a time, has found its
exact state. Waiting for that state, End on 4 MB of Python stood uncoloured for 2.1 s in
Chromium and 18.5 s in Firefox; it is now coloured two frames after it shows.

A document the page shows draws in the first task, and only hidden ones wait a task
each, so a reload on the 30th of 30 tabs of 4 MB shows its document at 0.64 s in
Chromium (was 2.8 s) and 2.4 s in Firefox (was 33 s).

Runs are coloured only while the listing has a box: Firefox reports a closed tab's runs
drawn, and coloured every document in a closed tab as the page loaded.

`tokenize` gives each language a highlighter of its own grammars, so a Markdown
fence's language is flat wherever it is coloured, rather than coloured when another
block had loaded its grammar. `syntax()` resolves to `{tokens, state}`, replacing
`syntaxState`.

The Find test now asserts that the opened document's lines carry syntax colour and the
unopened one's don't; it fails in both engines with colour turned off.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

test_shell_commands_share_colors_in_plain_code_widgets_and_diffs (tests/browser/test_render_anchors.py) fails on this head for two reasons. I ran it locally to check.

  • A syntax() consumer missed by the API change. That test calls syntax(src, lang) from window.__lfWidgetApi() in two places and still treats the result as the token array: tokens.map(t => t.text) throws TypeError: tokens.map is not a function for every language, and the heredoc check iterates the returned object as tokens. Both need .tokens. Its name matched none of the -k terms in the description's test run, which is why that run didn't catch it.
  • Shiki's singleton warning. With one highlighter per language, the same test, which tokenizes every registry language, creates 10 Shiki instances, and Shiki logs [Shiki] 10 instances have been created… with console.warn. The browser fixtures treat that as a failure, and so would the render gate on any page whose code covers about nine languages, counting the shared highlighter. One highlighter per language is a deliberate choice here, so the warning is noise: pass warnings: false to the per-language createHighlighterCore (inline suggestion) and rebuild browser/vendor/syntax.esm.js.

Comment thread build/entries/syntax/entry.mjs Resolved
…ared highlighter

Each token colour's highlight is named by the theme's colour variable, and
text-document.css declares its `::highlight()` rule, so painting never adds a rule.
Inserting one as each colour first appeared cost Firefox a whole-page restyle, 0.85 s
a rule beside a long document, and End's scroll appeared 1.5-1.9 s after the press.
tests/runtime/text-document-colours.test.mjs holds the declared list to the token
theme's; renaming a rule fails it.

Taking a run's paint off rebuilds each highlight it touches from the ranges it keeps:
Firefox finds a range to delete by walking the highlight's list, and deleting two runs'
ranges one by one took over 100 ms of a frame.

`tokenize` goes back to the highlighter every block shares: one per language raised
Shiki's "10 instances" warning on a page of ten languages and changed `lf-code` and code
blocks. A Markdown fence's language in a text document is coloured where another block
has loaded its grammar, as in `lf-code`. test_render_anchors.py takes `syntax()`'s
`.tokens`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@max-sixty
max-sixty marked this pull request as ready for review November 4, 2026 11:40

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

test_a_long_text_document_draws_the_lines_in_view_and_keeps_the_rest_whole[firefox_browser] fails some of the time on this head, and that is the red test job (run 41818130303). Firefox raises ResizeObserver loop completed with undelivered notifications. and the browser-problem collector fails the test at teardown. Run alone on this head it failed 3 of 14 times. On origin/main it passed 10 of 10, so this change causes it.

The page in that test has no language, so RunColours isn't involved. The error comes from the new listing's layout or sizing. Two candidates I tried didn't remove it, at about the same rate: moving the size observer's this.list(...) call into its nextFrame, and restoring this.refit() after setChildren(this, [view.figure]). The things still left are the new row box (min-block-size: 1lh, the padding, the absolute ::before number), the code.checkVisibility() gate in lineColumns, and the runs now being sized first from the observer rather than in the draw.

The error reports a size change made while the observer was delivering. The fix belongs in the widget, not as an allowance in the test.

The first sizing of the runs had moved to the size observer's next frame, so a shown
document's first frames stood its runs at a line a row. On Linux CI, Firefox then
reported "ResizeObserver loop completed with undelivered notifications" in
test_a_long_text_document_draws_the_lines_in_view_and_keeps_the_rest_whole (2 of 2
runs); it did not reproduce on macOS or in Playwright's Linux image on arm64. A document
the page shows is sized as it draws again, as on main; hidden ones still wait for their
listing's box, which keeps the closed tabs' layout reads off the load.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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