Skip to content

Colour only the documents on screen, and rewrite only the rows a new text changes - #6035

Merged
max-sixty merged 6 commits into
mainfrom
grind/text-document-costs
Nov 15, 2026
Merged

max-sixty merged 6 commits into
mainfrom
grind/text-document-costs

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

Two costs in lf-text-document grew with something other than what the user did: syntax colour grew with how many tabs the user had opened in the session, and a rewrite of a document's source grew with the document's length rather than with the lines that changed.

Colour: a closed tab gives up its document's colour

Every document on a page paints its syntax colour into the same few highlights, one per token colour. A document coloured the runs of rows in view and uncoloured them as they left it, but a closed tab never uncoloured. Since #5996 a fold (a closed tab's hidden="until-found" panel or a shut <details>) makes its runs content-visibility: visible, so they report nothing as it closes, and Chromium reported nothing under a fold before that. So each tab the user opened left its runs' ranges in the shared highlights for the rest of the session. Each uncolouring rebuilds every highlight it touches from the ranges it keeps (a Firefox delete walks the highlight's list), so it cost every range on the page, and Chromium's hit tests grew with them too.

A document now drops its colour when a fold closes over its listing. An IntersectionObserver rooted at the listing's pre watches its rows. They stop meeting the pre when a fold closes or the document leaves the page, and page scrolling never moves them out of it. Both engines report the close after the frame, checked with a fold of each kind.

A reopened tab still shows its colour in its first frame. When the fold closes, the document observes its listing's size afresh: a size observer reports only a change from the size it last reported, and the fold opens at that size, so without the fresh observation nothing reports the listing's box before the frame. With it, the size observer reports the box before the frame that shows the reopened tab paints. The document then reads which runs its view shows off their boxes (runsInView) and colours them in that frame. Reading them rather than keeping the runs shown before the fold also covers a rewrite made while the tab was closed: Firefox draws the reopened rows in the first frame, and with the kept runs, 22 of 22 rows in view stood uncoloured there.

The highlights now hold the ranges of the documents on screen, whatever the session has opened, so an uncolouring's rebuild costs what the window shows. The price is paid on reopening: a reopened document colours its runs in view again before the frame that shows it, about 8 ms in Chromium (72 → 80 ms from the press to the reopening frame, in the review's measurement).

Rewrite: a new text changes only the rows of the lines it changes

reconcileRuns built a fresh listing of every line, moved every kept row into the run the new text put it in (setChildLists), and reconciled every run's rows (setRenderedChildren), so a one-line rewrite of 50,000 lines did the work of 50,000. Runs held a fixed 128 rows, so lines added near the top moved that many rows across each later run's edge, and the runtime heard each move.

changes walks the old and new lines (with their endings) and returns each change as the old rows it replaces and the new rows that replace them, capped as before (MAX_EDIT_LENGTH). rewrite applies them last to first:

  • A row a change replaces keeps its node and takes the new words as its text's least edit (setRenderedChildren on the row), so a selection in the words it keeps stays.
  • Rows past the new ones leave. New rows past the old ones stand in the run of the row before them.
  • Runs no longer hold a fixed 128 rows; every run a rewrite didn't touch keeps its rows (regroup). A touched run folds onto the end of the run before it where the two fit in 128 rows or where it fell under 32, and a run filled to 256 splits into runs of 128. Without folding, 40 cycles of adding 200 lines and removing them took a 3,002-line text from 24 runs to 75 (the reviewer's measurement); with it, 40 cycles took it to 32 and 120 cycles to 40, every run at least 32 rows.
  • Folds and splits move rows through setChildLists, which holds a selection in a moved row, and a moved row lands only at a run's end or in a run the split has just made. Chromium drops the line number of a row moveBefore puts at the head of a run it skips, and numbers the rows after it from 1: that is what test_a_text_document_update_keeps_a_selection_it_carries_into_another_run[browser]: a drawn line number no longer matches its line #5916's test hit on main. notes/browser-support.md now records the gap with test_a_text_document_update_keeps_a_selection_it_carries_into_another_run[browser]: a drawn line number no longer matches its line #5916's reproduction and its recheck.
  • When the line count changes, each later run counts its numbers on from its new first line, which is counted from the rows before it, not read back from the page. The number now sits on the run's first row (--lf-lines-before, which the first-row counter rule already read) rather than on the run, so renumbering restyles one row per run. Held by the run, it reached every row, and Firefox, which styles the rows of runs it skips, restyled all of them: renumbering every run of the 50,000-line document took 190–240 ms to the end of the next frame in Firefox and 13–14 ms in Chromium, against 34–35 ms and 5 ms on the first rows.
  • Only the runs whose rows changed are sized again (sizeRuns).
  • The line each run starts on (starts) is counted where runs are made or regrouped and kept beside them, so syntax colour reads a run's lines without counting rows. Counted from the rows before each run instead, colouring the way to the end of 50,000 lines counted every row before each run it tokenized: walk took 52 ms in Chromium's profile, 45 of them counting, against 11 ms on base and 9 ms now (the tokenizer's own 330–340 ms is the same in all three).
  • A grammar state stands for its run while the run starts on the line it did and that line comes before the change. A rewrite drops the states and paint from the first run that holds the change, before it or after it, or that starts elsewhere; kept by place, a split's second part was coloured from the state of the run that had stood second, and a string opened above the split read as code below it.

Past the cap (refill), each run reconciles its rows with as many of the new text's rows at its place, as main did, and new runs of 128 hold the rows the new text adds. The reconciliation finds a row's words wherever they stand in its run, so a selection on lines a rewrite reindented and moved by a line stays on its words. An earlier version of this branch patched every row with the line at its place, and the selection moved to another line's words. The reconciliation also gives each row the new row's attributes, so each run's first new row carries its number in; patched bare, a rewrite past the cap that kept every run's first line (every line reindented, none added) left those runs unnumbered, and their rows counted from 1.

Evidence

Base 28c1812ddb and head were measured back to back in one session on one Mac (load average 22–28, so single readings are noisy), in Playwright Chromium 158.0.8127.18 (build 1254) and Firefox 159.0 (build 1572). The rewrite and colour paths measured there are unchanged by the review fixes, which touch only runs a rewrite changes (folding), rewrites past the cap, and reopening.

Colour after opening tabs

Page: 30 tabs in a side list, each an lf-text-document with language="python" bound to its own source of 20,000 lines of CPython stdlib modules. Each run serves a fresh copy, opens the last N tabs in turn by click (700 ms quiet after each), then scrolls the last opened document's listing 3000 px eight times. "Highlight methods" is the time spent inside the highlights' add, delete, clear and iterator over the eight steps, from wrapped methods. "Task" is the median of Chromium's TaskDuration per step.

Base, 1 tab Base, 30 tabs Head, 1 tab Head, 30 tabs
Colour ranges after the opens 746 10,449 380 380
Highlight methods, Chromium 2.0 ms 17.2 ms 1.5 ms 1.6 ms
Highlight methods, Firefox 27 ms 198 ms 30 ms 25 ms
Task per step, Chromium 36 ms 44 ms 33 ms 40 ms

Chromium CPU profiles of the eight steps, from an earlier run in the same session: on base, unpaint took 1.6 ms after one tab and 33.9 ms after 30, and elementsFromPoint 6.4 ms and 25.5 ms; on head after 30 tabs, unpaint stayed under 1 ms and elementsFromPoint took 6.2 ms. Firefox's per-step busy time swung by hundreds of milliseconds between steps on both arms under this load, so it isn't reported.

Rewrites of a 50,000-line source

Page: one lf-text-document with language="python" bound to 50,000 lines of Python. Each rewrite is a leaf data set, and the reading is main-thread busy time from the write until 700 ms quiet (gaps over 20 ms in a chain of zero timeouts). "Plain" leaves the listing at its top with no selection. "Selected" scrolls it to line 25,000 and selects a word there. Every rewrite on both arms left the listing's text equal to the source and the selection on its word.

Rewrite Chromium plain Firefox plain Chromium selected
Edit line 100 320 → 112 ms 1,673 → 334 ms 400 → 162 ms
Edit line 49,000 259 → 53 ms 484 → 149 ms 331 → 132 ms
Add a line at 200 267 → 51 ms 1,325 → 317 ms 385 → 148 ms
Remove a line at 300 284 → 59 ms 1,568 → 150 ms 368 → 154 ms
Add 200 lines at 500 2,548 → 72 ms 16,896 → 605 ms 2,502 → 151 ms

With a selection, base also lost the reader's place on the 200-line addition (the row in the middle of the listing changed), where head kept it. A rewrite past the cap (every line of the 50,000 edited) costs what it did on main: 1,503 and 1,582 ms in Chromium against 1,501 and 1,576 on base, and 4,248 and 4,169 ms in Firefox against 4,222 and 4,242, measured alone at load 6–7.

In Chromium's profile of the plain one-line edit, show took 8 ms on head (changes 3, splitting the source 3, rewrite 1), against 212 ms on base (reconcileRuns 193). What remains of the busy time is outside the widget's draw; see "What this leaves".

Colour stays right

Stills of the first document after load, after a 20,000 px scroll, with the second tab open, after switching back, after a rewrite that adds a line in view and edits another, and after a page revision are pixel-identical to base in both engines. While the second tab is open, the first document holds 0 colour ranges on head, against 962 (Chromium) and 714 (Firefox) on base. The JS heap after opening 30 tabs in Chromium read 212 MB on both arms in the back-to-back run, so the closed tabs' ranges are not a measurable share of memory here.

A tab whose document was scrolled to line 140 and then rewritten while closed (200 lines added at line 101) reopened with all 22 rows in view coloured in its first frame in Firefox, as on base; Chromium draws no rows in the first two frames after the reopen on either arm, and colours them when it does.

Tests

  • test_a_closed_tab_gives_up_its_document_s_colour_and_wears_it_as_it_opens (Chromium and Firefox): a closed tab's document holds no colour ranges, and when it reopens, every row in view holds colour in the frame that shows it and the three after, both plainly and after a rewrite made while it was closed. It times out on base in both engines, where the closed tab keeps its colour. In Firefox it fails without the fresh size observation, and with the runs kept from before the fold (22 of 22 rows uncoloured in the reopening frame).
  • test_a_text_document_rewrite_changes_only_the_rows_of_the_lines_it_changes (Chromium): a mutation observer on the listing sees one edited row for an edited line, one row added to one run for a line added at the head of a skipped run, one removed row for a removed line, and 100 rows added to one run for 100 lines. Then a run splits, the text stays the source, and the drawn numbers count every row at the added line and at the end. Last, a rewrite past the cap that adds a line at the top and indents every line keeps a selected line's words selected, and one that only reindents every line leaves the drawn numbers counting every row. It fails on base at the added line, where every later run gained and lost a row; on this branch's first version at the selection past the cap ("line 700" against "line 701"); and on its second at the numbers after the reindent.
  • test_a_split_run_colours_from_its_own_grammar_state (Chromium): a triple-quoted string spans the point where a later rewrite splits its run, and an edit below the split leaves its rows coloured as a fresh load colours them. It times out on 84b6ba3, where the second part kept the state of the run that had stood second.
  • tests/runtime/text-document-lines.test.mjs now tests changes, which replaces keptLines.

test_a_text_document_update_keeps_a_selection_it_carries_into_another_run[browser], which #5916 tracks failing on main, passes on this branch in both engines. On base, in the same session, the third run's first row (line 257) draws no number and the rows after it count from 1 (lines 258–280 read 1–23), after a row moved into that run's first place.

Ran: the tests above; 51 browser and journey tests that read a text document (this branch's selection, by grepping tests/browser and tests/journeys for text documents, their row selectors and helpers, merged with the reviewer's; 74 cases with their engines): all pass but test_each_sampled_focus_ring_is_shown_whole_in_its_surface, which fails the same way on base; tests/runtime/text-document-*.test.mjs; pnpm run check:browser; pre-commit on the changed files. A stress of 120 random edits (edits, insertions, deletions and moves of up to 80 lines) and of 120 add-and-remove cycles on a 3,002-line document left the text equal to the source and every drawn number right at four places in each.

What this leaves

  • After a rewrite, syntax colour still tokenizes again from the first changed line down to the view (RunColours.walk, in 8 ms slices). With the reader at line 25,000, an edit at line 100 spent about 130 ms of Chromium's main thread there, and the runs in view showed colour from a fresh grammar state until the walk reached them. Comparing the grammar state each run ends in with the one kept from before the rewrite could stop the walk at the changed run.
  • Outside the widget, each update still does work that grows with the document. The keyboard scopes walk the document's rows after it draws (claimPaintedRoots, 17 ms in Chromium on 50,000 lines), and with a selection in the document, the command hints resolve its passage against the document's text (selectionAnchor → segmentsIn, about 75 ms).

Calls Max may reverse

  • Runs hold 32 to 255 rows after a rewrite rather than exactly 128 (a run no rewrite touched, or the first run, can hold fewer), folded and split by the thresholds above.
  • A run's first line sits on its first row (--lf-lines-before), and a row that stops being first keeps a value the stylesheet doesn't read.
  • A reopened tab's colour returns through a second observation of the listing's size, armed when the fold closes, and a read of the runs' boxes as it opens.

Not verified

  • WebKit and Safari: not run.
  • Release Firefox, as opposed to Playwright's build.

Closes #5916. Part of #5194.

…text changes

A closed tab kept its text document's syntax colour in the highlights every document
shares, so each tab opened in a session added ranges that every later uncolouring
rebuilt. A document now drops its colour when a fold closes over its listing, which an
IntersectionObserver rooted at the listing's `pre` reports, and observes the listing's
size afresh so a reopened tab is coloured in the frame that shows it. After opening 30
tabs of 20,000-line Python documents the highlights held 380 ranges rather than 10,449,
and the highlight methods over eight scroll steps took 1.6 ms rather than 17.2 in
Chromium and 25 ms rather than 198 in Firefox.

A rewrite reconciled every row and kept runs at 128 rows, so lines added near the top
moved rows across every later run's edge. `changes` now walks old and new lines into
changes of rows, and `rewrite` applies them in place: a replaced row keeps its node and
takes its text's least edit, added and removed rows stand or leave where they are,
runs grow and split at 256 rows rather than shifting rows, and each run's first line
sits on its first row, so renumbering restyles one row per run in Firefox. On 50,000
lines of Python with the listing at its top, a one-line edit took 112 ms rather than
320 in Chromium and 334 rather than 1,673 in Firefox, and 200 added lines 72 ms rather
than 2,548 and 605 rather than 16,896.

The update selection test #5916 tracks now passes. On base, after rows moved into an
existing run's first place, Chromium drew that run's numbers from 1; rows now move only
into the new runs a split makes.

Closes #5916. Part of #5194.
… view, and fold small runs

A rewrite past MAX_EDIT_LENGTH patched each row with the line at its place, so a rewrite
that added a line at the top and indented every line moved a selection onto another
line's words. Past the cap, each run now reconciles its rows with as many of the new
text's rows as main did (`refill`), which finds a row's words wherever they stand in its
run; the rewrite test now selects a line, rewrites past the cap, and checks the words
stay selected (it read "line 700" for "line 701" before).

A reopened tab coloured the runs it showed before the fold, so after a rewrite made
while it was closed, Firefox drew the rows now in view uncoloured for a frame or two
(22 of 22 in the reopening frame). As the listing takes a box, the runs in view are
read off their boxes (`runsInView`) and coloured before that frame paints; folds and
splits also pass a drawn run on to the runs its rows move into. The colour test checks
every row in view at the reopening frame and the three after, plainly and after a
rewrite while closed.

A touched run now folds onto the end of the run before it where the two fit in 128
rows or it fell under 32 (`regroup`): 120 cycles of adding and removing 200 lines took a
3,002-line text from 24 runs to 40, where unfolded 40 cycles took it to 75. Rows move
only onto a run's end or into a run a split has just made, since Chromium drops the
number of a row `moveBefore` puts at the head of a skipped run (#5916);
notes/browser-support.md records that with #5916's reproduction and a recheck. A run's
first line is counted from the rows before it rather than read back from its first
row's style, and the rewrite test asserts how many rows and runs change rather than
which run.

Part of #5194.

@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.

Two findings in RunColours, both from runs no longer being a fixed 128 rows. Details are inline.

  1. The colour walk now grows with the square of the page. walk and #paint call firstLines(code) for each run they tokenize. That call reads every run's childElementCount, and in Chromium childElementCount itself walks the children. So walking down to the view does work proportional to runs × rows. On base this was at * RUN, which is O(1). Root AGENTS.md, Responsiveness, names this shape ("a step that walks one of those collections for each member of another"). The run starts change only through a rewrite, and every rewrite reaches changed(), so computing them once there and reading them from this keeps the walk linear.
  2. A split can keep a grammar state that no longer belongs to its run. changed() keeps states[0..runAt(from)]. If from falls in the second part of a run that regroup split, the kept states[k+1] is where the old run k+1 started, but the new part starts mid-way through old run k.

max-sixty added a commit that referenced this pull request Nov 15, 2026
… costs (#6033)

`leaf-dev bench` now generates #4781's page, a side list of tabs each
holding a large text document bound to its own source, and measures the
inputs that found this week's costs on it by hand. The daily `bench` job
runs it, so Tend's review sees these costs grow with the page.

## The page

`documents` holds the shown document, one more in a closed tab for each
eight of `n`, and one more again: 3 documents on the BASE page, so
`reveal` has two closed tabs to open there, then 10, 18 and 34 at the
daily sizes 64, 128 and 256, about #4781's 30 tabs at the largest. Each
source is 2,048 lines of Python (16 of a listing's 128-row runs), the
same at every size. So a cost that grows with the documents a page holds
grows with `n` and shows in the exponent. A cost that grows with the
length of the one document opened stays level and shows only beside
another arm (`--base`).

The largest page holds 69,000 rows where #4781's held 2.9 million. That
is enough for a walk of every panel on each tab switch (#5996) to fit an
exponent in Chromium, and it keeps the daily run short (below). The text
is Python rather than #4781's Markdown, because Python's syntax colour
paints most words, and the colour a closed tab keeps is what `browse`
reads.

The sources are set through the fixture's data companion
(`page.data.json`, which `prepare_page` sets with `leaf data set`), so
each arm builds the page with its own Leaf. `Collection` gains `data`
for it, which `server_paths.build` also sets in process.

## The inputs

| Input | What it does | Fix it watches |
|---|---|---|
| `data` | the agent's `leaf data set` changes the first line of the
shown document's source; `painted` is the frame that draws the new line
| #5992 |
| `reveal` | a click opens the second tab, then the third, neither
opened before | #5996 |
| `search` | the first `/`, which opens page search | #5999 |
| `matches` | type `value`, which every line holds, into page search,
until the count is final | none yet |
| `browse` | put away page search, open every closed tab, then turn the
wheel a run's height down and up the last one's listing, 16 steps |
closed tabs keep their colour ranges (still on main; #6035) |

They run in that order, so `search` and `matches` read the page before
`browse` has opened every tab, whose kept colour every later input would
meet. They need the page's own ids (`#docs #d0[source]`) and find the
other tabs and documents by them. Each finds what it acts on through
`page.evaluate`, never a locator, since a Playwright locator walks every
element of the page for each query. `holds`, which decides whether a
page has what an input needs, now asks the document with `querySelector`
for the same reason. `painted.js` gains three facts: `shows` (an element
is drawn and holds some words), `searching` (page search's field holds
the caret) and `searched` (its count is final). `BenchPage.written`
takes the file a command writes, here the source's file rather than the
log.

## What the marks hold

`held` now covers the requests and bytes any input causes, the size of
the answer to each of its POSTs (`<input> event KB`) included, besides
the CPU of an input the browser answers alone: root `AGENTS.md`,
"Responsiveness", holds an input's work to what it changes. Without it,
#5992's cost, every source sent to the tab after a write to one, fits
exponent 1.08 with no mark, since an agent's write may grow with the
page. An input whose result is the whole page is exempt, through a new
`Input.whole`: `revision` and `stamp`, which carry the new document, and
`matches`. A held count's noise floor is a quarter of its own reading on
the BASE page and at least one, where every count's was a fixed 10 KB or
one request.

Re-judged under main's rules and this branch's, the nine daily reports
of 11-06 to 11-14 differ in one reading: `asks` `comment event KB`, 4.9,
8.1, 11.9 and 19.6 KB across the sizes in the six reports of 11-06 to
11-11, now marked at 1.08. Those reports showed it with no mark; it
reads level from 11-12 on. On this page's runs the only differences are
`matches`, which `whole` lets grow, and `data KB` with #5992 reverted.

## Evidence

All on this Mac (M5 Max, 18 cores, load average 3–21 from other
sessions), `uv run leaf-dev bench documents --sizes 64,128,256 …`.

Current main, Chromium, the daily job's command (`--rounds 2 --input
data --input reveal --input search --input matches --input browse`), 266
s:

```
                            8         64        128        256   exponent
elements               6435.0    20988.0    37620.0    70884.0         - 
load cpu ms             200.0      242.8      299.5      510.5      1.43 
data cpu ms              23.1       21.3       25.5       30.7         - 
reveal cpu ms            46.0       42.0       43.9       47.1         - 
search cpu ms            18.3       17.3       18.4       19.7         - 
matches cpu ms          290.5      718.7     1271.1     2328.5      1.13 
browse cpu ms            15.4       19.5       25.4       28.0      0.81!
data painted ms         133.5       99.9       68.6       99.5         - 
data requests             1.0        1.0        1.0        1.0         - 
data KB                  82.6       82.6       82.6       82.6         - 
reveal painted ms        37.2       33.5       34.8       36.1         - 
reveal requests           0.0        0.0        0.0        0.0         - 
reveal KB                 0.0        0.0        0.0        0.0         - 
```

Current main, Firefox, the first commit's page and input order with
`--browser firefox`:

```
                         8         64        128        256   exponent
elements            4351.0    18904.0    35536.0    68800.0         - 
load cpu ms          344.8      521.9      557.5      917.8      0.85 
data cpu ms           40.6       56.2       43.4       52.0         - 
reveal cpu ms         73.5       78.3       65.0       71.7         - 
browse cpu ms         43.9       51.4       54.6       68.1         - 
search cpu ms         37.5       61.3       40.8       48.5     -0.56 
matches cpu ms        98.3      115.0      201.3      287.1      0.87 
```

What main shows, with a V8 profile of each growing input from
`--profile`, which lists the functions whose time grew past the input's
limit from the smallest page to the largest:

- **`browse`, 0.81 `!` in Chromium**, and 0.96 and 1.04 in two runs of
`browse` alone. A closed tab keeps the colour ranges of the runs it last
showed (896 a tab here), and each run a step colours rebuilds highlights
holding every opened tab's ranges. The profile names `unpaint` and
`follow` (`lf-text-document.js`), 3 to 40–45 ms. This is the cost
#5996's body left unmeasured, which #6035 removes: with its change,
review read `browse` level. Firefox grows too (44 to 68 ms), but under
the noise floor in one of two runs.
- **`load cpu`**, 1.43 here and between 1.02 and 1.71 across seven runs
on main, above 1.5 in two. The profile names an anonymous function at
`addressable-names.js:187`, `headingsIn`'s query of every heading under
an element, growing from 1 to 126 ms (exponent 1.54). Read from the
code, not confirmed: each document's first draw may start a new page
reading, whose heading queries walk the whole page again.
- `matches` grows at 1.13 in Chromium and 0.87 in Firefox, within its
limit as a `whole` input. Chromium's 2.3 s at 34 documents against
Firefox's 0.29 s is #5999's note that a match's visibility read styles
each run it lies in.
- `search`, `data` and `reveal` stay level in both engines. In the first
commit `search` ran after `browse` and grew with the tabs `browse` left
coloured (0.79 `!`); run before it, it reads 17 to 20 ms.

Each fix reverted in the working tree (`git revert --no-commit`), with
`--base HEAD` for main beside it. The #5992 and #5999 rows are from the
first commit's page, which held one document fewer:

- **#5992**, Chromium: `data KB` goes 164, 736, 1,398, 2,722 KB with the
fix reverted, exponent 1.08 `!`; main reads 82.6 KB at every size.
- **#5996**, Chromium, two rounds, this head's page and `reveal`:
`reveal cpu` goes 48, 50, 63, 84 ms with the fix reverted, exponent 1.25
`!`; main reads 48, 43, 51, 49 ms. On the first commit's page, whose
`reveal` reopened the first tab for its second sample, the revert read
1.77 `!`. In Firefox the revert raises `reveal cpu` to 210–290 ms at
every size from 60–90 ms, level rather than growing, since the Firefox
half of #5996 (the fold rule) scaled with the opened document's length,
which this page holds fixed.
- **#5999**, Firefox, two rounds: `search cpu` goes 45, 83, 92, 165 ms
with the fix reverted, exponent 0.82 `!`; main reads 26, 30, 28, 24 ms.

## CI time

The daily job measures `documents` in a step of its own after the
default pages, with only these five inputs, since the `document` page's
text already grows under every other input. The step runs after a failed
one, and the readings to chart are collected once both have run, so one
page's failure keeps the other's chart. Its table goes to
`documents.txt` in the `bench-report` artifact, which Tend's benchmark
review (`.claude/skills/running-tend/SKILL.md`) now names beside the
browser and server tables. The command took 266–284 s here. To scale it
to the runner: the `rows` page with the daily job's arguments took 397 s
here and 7.5 minutes on the runner on 2026-11-14, a ratio of 1.13, while
the runner's load CPU is 2.2 times this Mac's. So the job should grow by
between about 5 and 10.5 minutes, nearer the first, since most of a run
is waiting rather than CPU.

## Not verified

- The runner's time for the new step, which the first daily run's step
timings will show.
- Firefox on CI. The Firefox clock (`ContentClock`) reads macOS's thread
times, so the daily job reads Chromium only, and a Firefox-only cost
such as #5999's shows only in a local run.
- WebKit.

No `dev/tests` smoke test: the bench has none, and each input ran here
in both engines at four sizes.

## Calls Max may reverse

- `held` covering requests and bytes, with `Input.whole` to exempt a
revision and a search.
- The CI step's input list, rather than every input on this page.
- Python content, 2,048 lines a document and `2 + n/8` documents.
- `browse`'s 16 steps, which over two runs fitted 0.96 and 1.04 where
three runs of 8 fitted 0.49 to 0.75.

Part of #5194.
Past the cap, refill reconciles each run's rows with fresh rows, and the
reconciliation gives each row the fresh row's attributes, so the first row lost its
--lf-lines-before. Where the run kept its first line and first row, regroup didn't
number it again, and a reindent of every line left those runs counting from 1. The
first fresh row of each run now carries its number in (number takes the row). The
rewrite test reindents every line past the cap and checks the drawn numbers; it fails
on the previous commit.

Part of #5194.
@max-sixty
max-sixty marked this pull request as ready for review November 15, 2026 11:06
…ale grammar state

Syntax colour found a run's lines by counting the rows of every run before it, each
time it painted or tokenized a run. Chromium counts an element's children one by one,
so colouring the way to the end of 50,000 lines grew with the runs times the rows:
`walk` took 52 ms in Chromium's profile, 45 of them counting, against 11 ms on main.
The line each run starts on is now counted where runs are made or regrouped
(`listing`, `regroup`), kept beside them, and handed to the colour with each new text
(`changed`) and to `sizeRuns`; `walk` takes 9 ms. A rewrite counts only the rows of the
runs it touched.

A rewrite kept the grammar states through the run holding its first change, by place.
When that run had split and the change fell in its second part, the kept state was
where the run that had stood second began, not where the new part does, so a string
opened above the split was coloured as code below it. A state now stands for its run
while the run starts on the line it did and that line comes before the change, and the
states and paint go from the first run that holds the change, before the rewrite or
after it, or that starts elsewhere. test_a_split_run_colours_from_its_own_grammar_state
checks a triple-quoted string across a split against a fresh load; it times out on the
previous commit.

Part of #5194.
leaf-agent
leaf-agent previously approved these changes Nov 15, 2026
The test's last wait passed its own timeout, which the suite's source check refuses: a
wait takes the suite's deadline. It now waits for row 258 to carry a string's colour
and compares the rows with the fresh load's once, so the previous commit's stale state
fails at once with the rows' colours in the diff.

Part of #5194.
leaf-agent
leaf-agent previously approved these changes Nov 15, 2026
Conflict in tests/browser/widgets/test_code_and_documents.py only: this branch and
#6041 each added a test after test_opening_a_closed_tab_draws_only_the_lines_in_view
(the closed tab's colour test and the Tab-stop test). Both are kept, each with its own
engine parametrization.
@max-sixty
max-sixty merged commit badc6f3 into main Nov 15, 2026
5 checks passed
@max-sixty
max-sixty deleted the grind/text-document-costs branch November 15, 2026 12:08
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.

test_a_text_document_update_keeps_a_selection_it_carries_into_another_run[browser]: a drawn line number no longer matches its line

2 participants