Repository navigation
Show a page of large text documents at once, with every tab's text in Find's reach - #5314
Conversation
… 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
left a comment
There was a problem hiding this comment.
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 callssyntax(src, lang)fromwindow.__lfWidgetApi()in two places and still treats the result as the token array:tokens.map(t => t.text)throwsTypeError: tokens.map is not a functionfor every language, and the heredoc check iterates the returned object as tokens. Both need.tokens. Its name matched none of the-kterms 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…withconsole.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: passwarnings: falseto the per-languagecreateHighlighterCore(inline suggestion) and rebuildbrowser/vendor/syntax.esm.js.
…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]>
leaf-agent
left a comment
There was a problem hiding this comment.
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]>
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-documentholds 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 anlf-text-documentbound to its own source, with a word at the top and foot of each source for Find.allholds 4 MB a source in lines of 300–600 words;shortholds the same 4 MB in lines of about 80 characters, 1.5 million lines in all;mdholds 400 KB a source of 80-character Markdown withlanguage="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.allshortmdallmdshortFirefox
shortis from an earlier round of this branch, before the review's fixes, which change nothing on a page with nolanguage; 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.findreaches a word only the last, unopened tab's document holds, selects it there, and opens that tab, on this branch as on main. Chromium'swindow.findsearches nohidden="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 dailytest_scaling.py.leaf-dev scalingfailed 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/eventanswers it reads, so the tab now raises the buffer before loading the page; the daily test shares thatmeasure.Calls for you
These are what the change costs a reader, each kept on purpose:
::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, whilelf-codeand 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.unread-syntaxreads token spans, and a text document has none; the same palette is still checked wherever code blocks orlf-codestand.What changed in the widget's contract
listingbuilds apre > codeof runs of 128 rows; a row is adivholding 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, solistingSheet,scopedSheetand Load pages of many text documents in Firefox without restyling the page per document #5226's shared-sheet adoption go.pierre.jsand the Pierre bundle stay forlf-diff.::beforegenerated 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, andtest_a_text_document_update_keeps_a_selection_it_carries_into_another_runnow 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.RunColourstokenizes 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 aStaticRangein oneHighlightper token colour, named by the theme's colour variable (lf-token-syn-keywordand so on).text-document.cssdeclares the::highlight()rule for each, andtests/runtime/text-document-colours.test.mjsholds 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 oncewalkfinds it. A new text keeps the paint and states before its first changed line. Tokens come from the highlighter the page's code blocks andlf-codeshare, so a Markdown fence's language is coloured where another block on the page has loaded its grammar, as inlf-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 andtest_render_anchors.pytake.tokens.short.content-visibility: auto,sizeRunsand its forgetting,reconcileRunsand the selection it carries across runs, the runtime'sdrawForLanding/skippableBox(untouched), the bounded viewport,holdSourceandcut, 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 stillsoncaptured-sourceand 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,ttravel and a live data update in both engines and schemes.Checks run
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 pytestontest_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.pyandtest_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_diffsamong 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_openednow asserts the opened document's lines carrylf-token-*ranges and the unopened one's carry none; withRunColours.followa no-op it fails in both engines.test_code_wrapping_keeps_source_copy_and_reader_choicefailed the same way on main then (a tap on the shortcut list's Copy code timed out).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
window.findthere searches no fold.StaticRange, shadow root), but no text-document test or still did.test_scaling.pywith the newdocumentaxis and the buffer fix was not run as the daily suite runs it, onlyleaf-dev scaling document --baseandleaf-dev scaling asks --sizes 32.Found along the way, not changed here
<p>tomainon theallpage costs Firefox 157 a 2.6 s style flush on main and about 0.27 s here, and 6–16 s onshort; 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 ofshort's load spent most of its time in style flushes that the runtime's visibility reads force (skippedinshown-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.shortin Chromium, keyboard-scope marking (markScopedIn,keyboard/scopes.js) took about 1.0 s and thewatchArrivals("*")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.sizeRunsresizes 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-beforeon 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.shortis 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.lf-diff; its bundle andpierre.jscould 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.