Repository navigation
fix: Stop the column's room lengths inheriting past the blocks that read them - #5609
Merged
Merged
Conversation
…ead them Only a block standing directly in a column or flow reads --lf-free-start and --lf-free-end, but they inherited through every box under the column. In Chromium 156 an inserted element then restyled every box below it: 2,500 elements cost about 29 ms. Every box whose parent is not a column or flow now sets the room back to zero, which subsumes the rule that did so for a flow outside a column's flow. The insertion now takes about 2 ms. Closes #5608
max-sixty
added a commit
that referenced
this pull request
Nov 7, 2026
…#5622) The column states the room on each side of it in its own direction (`--lf-free-start`, `--lf-free-end`), and a flow in it read those as its own start and end. So a flow written the other way from its column took the room from the wrong side. Beside a contents map, where all the room is on one side, a right-to-left question or `layout-flow` section on a left-to-right page grew toward the map: its available block stood at -334 to 1032 in a 1726px window, 334px past the left edge, and its wide block covered the map. A left-to-right flow on a right-to-left page did the same on the right. The column now also states the room by side (`--lf-free-left`, `--lf-free-right`), and each flow takes its start and end from those in its own direction. A flow written either way now reaches the same room as the page's own blocks, and a wide block whose end faces the map keeps to the prose. In a centred column both sides hold the same room, so nothing there moves: the probe read the same boxes on base and head in Chromium and Firefox. The two new lengths reset with the others below the blocks that read them (#5609), and a forced restyle on 100 paragraphs of 24 words took 1.4–1.5 ms on base and head alike. `test_a_flow_written_the_other_way_grows_toward_the_room` covers both page directions and fails on main. The 101 breakout, note, table, sidebar and obligation tests in the render and layout files pass. > _This was written by Claude Code on behalf of max-sixty_
max-sixty
added a commit
that referenced
this pull request
Nov 11, 2026
… row (#5818) Resolving a thread no longer restyles every element of the page, and sending a comment no longer restyles every margin row. On the generated asks page at 1,024 sections in Chromium, Resolve's style work drops from 841 ms to 16 ms in a profiled run, and Send's from 125 ms to 39 ms. ## Why Profiling the margin on the generated asks page found two restyles whose cost grew with the page, separate from #5817's margin work: - **Resolve** forced one style recalc of 185,554 elements (744 ms) at 1,024 sections, read by `landingBand` in `reading-regions.js`'s `pageGeometry`. - **Send** restyled every margin row, first under `holdSelection`'s read of the selection (46 ms) and again under `marginColumn` (6,176 elements). ## Causes Neither restyle came from the code that read the style. Each read forced a recalc that an earlier DOM write had made large; Chromium's invalidation tracking names the writes. **Resolve.** Resolve closes the card and returns focus to the thread's passage. `paintFocus` (focus.js) marks every ancestor of the focused element `data-lf-focus-within`: the paragraph, its section, the article and `main`. reading.css's fade beside a table's sticky row names is keyed on that mark: ```css &[data-lf-more-before]:not([data-lf-focus-within]) > * > tr > :first-child::after ``` Its last compound names no type, class, id or attribute, so when the mark changes on an element, Chromium restyles every element under it. With `main` marked, that is the whole page. `landingBand`'s `getComputedStyle(root)` was the next style read in the frame, so it paid the recalc. The `data-lf-floating-editor` attribute and the `calc(0 * var(--lf-landing-top))` padding from #5580 play no part. With the rule dropped, the same mark change restyled 980 elements on a 40-section page instead of 7,185. That residual has a second cause, on pages whose `main` carries a column Layout (the asks page has none, so the bench doesn't show it). Every restyle of `main` restyled the boxes under it, even a restyle that changed nothing: 246 elements at 10 sections, and 6 with the room set to a constant. The column's room, `--lf-free-start` and `--lf-free-end` in layouts.css, is a length less a percentage registered as `<length-percentage>`, and Chromium 158 counts that value as changed each time it is recomputed. A plain page reproduces it: a no-op restyle of a parent declaring `--free: calc(10px - 50%)` restyles all 200 children; with a plain length, a plain percentage or `syntax: "*"`, it restyles the parent alone. Focus marking `main` restyles it, so on a column page Resolve still restyled the whole column. **Send.** The frame-edge rules in reading.css are bare compounds: ```css :nth-child(1 of :not(.lf-ui, [data-lf-gen])) :nth-last-child(1 of :not(.lf-ui, [data-lf-gen])) ``` Chromium matches them against every element, whether or not the frame's container query holds. Once it has evaluated `:nth-child()` for a parent's children, it restyles all of them whenever a child is inserted or removed. Send removes the comment's row from the margin toolbar and inserts the thread's row, so every row in the toolbar was restyled, and Resolve's removal of the row did the same. `holdSelection`'s read of `rangeCount` was the first read after the insertion. ## Fix All three are CSS changes at the rule that owns the invalidation: - reading.css: the row-name fade and its `data-lf-more-before` background rule end in `:where(th, td):first-child`, so a mark on an ancestor restyles only first cells. `:where` keeps the rules' specificity. - layouts.css: the column computes its room in two new non-inheriting `<length-percentage>` properties, `--lf-room-start` and `--lf-room-end`, so every unit in it (the shell's `cqi`, and a page's `--col`, `--col-pad` or `--aside` in `ch`, `em` or `rem`) resolves on the column, as on main. It passes the result to its children in `--lf-free-*`, now registered `syntax: "*"`, so children inherit a fixed expression of lengths and a percentage that Chromium compares by value, and each reader resolves the percentage against its own containing block, as before. A non-inheriting value that Chromium counts as changed restyles only the column. notes/browser-support.md records the engine gap and how to recheck it. The comment on the reset rule after it (#5609) loses its performance reason, which was the same gap, and keeps its job: without the reset, a flow inside a plain wrapper breaks out of the wrapper ([168, 888] becomes [24, 1416]). - reading.css: the frame-edge rules check `:where(:not(.lf-ui, [data-lf-gen]))` before `:nth-child()`. Chromium stops at the first failing part of the compound, so it never evaluates the position for chrome, and the toolbar is no longer marked. `:where` keeps the specificity: a plain `:not()` raised it and beat a `margin-bottom: -15px` on the pr-walkthrough diagram, which `leaf-dev stills` caught. `landingBand` and `holdSelection` are unchanged. With the invalidations fixed, `landingBand`'s read restyles 25 elements at 1,024 sections, and `holdSelection`'s read no longer appears among the forced recalcs. ## Before and after `uv run leaf-dev bench asks --sizes 256,1024 --input resolve --input comment --rounds 2 --base origin/main` at the head with the review fix (96f89a5), interleaved, lowest of two rounds, load average 4.0 at the start and 3.1 at the end: | reading | 256 main | 256 this | 1,024 main | 1,024 this | |---|---|---|---|---| | resolve, main-thread CPU ms | 321.9 | 155.0 | 1,162.9 | 480.7 | | resolve, input to painted ms | 243.9 | 134.2 | 900.9 | 244.2 | | resolve, input to server's reading shown ms | 305.7 | 134.2 | 1,131.8 | 461.9 | | comment send, main-thread CPU ms | 153.0 | 143.6 | 478.7 | 440.0 | | comment send, input to server's reading shown ms | 158.7 | 154.5 | 497.3 | 453.8 | The first commit's three-round run read the same within a few percent (resolve painted 897.5 → 244.0 ms at 1,024 sections). At 1,024 sections, the forced style and layout in the long frames after Resolve fell from 644 ms to 6 ms. Send's gain is the row restyle alone (about 40 ms); the rest of its time is script the profile attributes elsewhere, and both inputs still take over 100 ms to show the server's reading at 1,024 sections. A profiled run of head at 1,024 sections, against the profile that found the problem: | | before | after | |---|---|---| | Resolve, style ms (forced) | 841 (797) | 16 (14) | | Resolve, largest forced recalc | 185,554 elements, `landingBand` | 222 elements, card close | | Send, style ms (forced) | 125 (78) | 39 (35) | | Send, recalc under `marginColumn` | 6,176 elements | 38 elements | | `holdSelection` self time | 45 ms | not in the top functions | The column-Layout cause doesn't show in the bench, whose page has no Layout. The new resolve test reads it: with `--lf-free-*` registered `<length-percentage>` again, a page of 24 sections restyles 120 more elements than one of 4. ## Tests Two tests in `tests/browser/test_chrome_contracts.py`, beside #5580's floating-editor test, count the elements Chromium restyles for one input on pages of 4 and 24 sections of questions in a column page's article, and fail if the larger page restyles 10 or more elements more. They run with reduced motion, so the card doesn't ease in over a host-dependent number of frames, and without the shift watch, whose cameras inserted into the chrome are restyles of their own. With all fixes the counts are equal at both sizes. | test | with the fixes (4 → 24) | fails without | |---|---|---| | `test_sending_a_comment_restyles_only_the_rows_it_changes` | 2,147 → 2,147 | the frame-edge guard: 2,150 → 2,170 | | `test_resolving_a_thread_restyles_what_focus_marks` | 1,178 → 1,178 | the row-name types: 1,894 → 4,294; `--lf-free-*` registered `<length-percentage>`: 1,196 → 1,316; the frame-edge guard: 1,181 → 1,201 | A third test, `test_a_column_stated_in_font_units_gives_every_breakout_the_same_room` in `tests/browser/test_render_pages.py`, holds the room's units to the column. On a column page and a sidebar page with `:root { --col: 50ch; --col-pad: 2em; }` at 1600px, three blocks that break out, in the page's font, a 10px monospace font and 24px, must reach the same edges, and the page must not scroll sideways. It passes in Chromium, Firefox and WebKit, and failed in all six cases on this branch's first commit, which registered the room `*` without resolving it on the column: the column page's blocks stood at [20, 1580] and [48, 1552] beside [34, 1566], and the sidebar page's monospace block ran to 1738px. ## What I checked - The two restyle tests, and #5580's floating-editor restyle test, after the review fix as well. - 92 browser tests selected by `-k "resolv or landing or floating_editor or floating_comment or restyle"`: 90 pass. `test_a_resolve_s_notice_stands_for_that_resolve_alone` fails here with and without this change (main's CSS restored, by node id), so it is inherited. - 56 tests in `test_render_pages.py` that read the column's room (breakouts, notes, sidebar, tracks and the new font-unit test, `-k "breakout or room or note or sidebar or available or wide or column or track or font_units"`), on Chromium, Firefox and WebKit, and the two sticky row-name tests: all 58 pass. - On the first commit, `leaf-dev stills` for `breakout-captions-scrolled`, `table-scrolled-sideways`, `release-notes`, `pr-walkthrough`, `breakout-table-caption`, `sidebar-contents`, `gallery-wide-passage` and `proxy-note-paragraph`: 0 px changed. `table-scrolled-sideways` lists one DOM difference, the comment box's resting label; `leaf-dev probe` shows head without this change lacks it too, so it is capture timing. - `pnpm run test:runtime` (913 pass), and pre-commit on the changed files. An independent review re-ran `leaf-dev stills` on this head: 30 states in Chromium and WebKit, and 26 in Firefox, leaving out four that never settle in Firefox on main either. No state shows a layout change. One Firefox state, github-discoveries, shows glyph-edge raster differences (216 px, at most 26 of 255 levels) with every box and computed style identical. Not checked: Firefox and WebKit restyle counts (both fixes are Chromium invalidation behavior; the layout tests above hold the values in all three); the broad suite, which CI runs. ## Follow-up, not in this PR Each focus move still restyles about 6 elements for every block before the focused one, on a page whose blocks are `main`'s children: 92, 272 and 992 elements at 10, 40 and 160 blocks. Thirty `:has()` rules in 12 files name a focus mark (`data-lf-focus`, `data-lf-focus-visible` or `data-lf-focus-within`) in their argument, so Chromium starts a `:has()` invalidation walk on every focus move, and broad `:has()` subjects, such as `:has(> [data-lf-track])` in layouts.css among others, make that walk visit the preceding blocks. Fixing it means keeping focus marks out of `:has()` arguments or narrowing those subjects, a change across many rules. > _This was written by Claude Code on behalf of max-sixty_ https://claude.ai/code/session_01GQAnFBpRfi8Gh5cgPofNzs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The column's room lengths,
--lf-free-startand--lf-free-end, are read only by a block that stands directly in a column or flow (a breakout, a note row, a nested flow). They were inherited by every box under the column, though. With that inherited percentage expression on 2,500 boxes, Chromium 156 restyled all of them whenever an element was inserted into a box among them. Now every box whose parent is not a column or flow sets the room back to zero. That one rule replaces the old one that did the same only for a flow outside a column's flow. The room still inherits from a column to its children and from flow to flow, so the WebKit resize behaviour recorded innotes/browser-support.mdis unaffected.Measured on the issue's page (one part's
article.layout-columnholding 100 paragraphs of 24<span>words), exported and driven in Playwright's Chromium: appending one absolutely positioneddivto the block and forcing layout took a median of 28.9 ms before the change and 2.3 ms after. That matches the issue's 1.7 ms with the descendants neutralised by hand.Verification
tests/browser/test_render_pages.pypass: 45 tests, includingtest_a_breakout_grows_only_from_a_holder_that_spans_the_columnandtest_a_table_granted_room_stands_on_the_prose_axison Chromium, Firefox and WebKit.tests/browser/test_render_gate.py: 76 pass.test_scrollbar_clearance_reads_generic_content_and_open_shadow_wordsfails the same way onmainwithout this change.leaf-dev bench. The measurement script appends a div 30 times and readsperformance.now()arounddocument.body.offsetHeight.Closes #5608 — automated triage