Repository navigation
Run no margin layout pass for the runtime's own marks and key hints - #5359
Merged
Merged
Conversation
…roke that moves no seat Scrolling moves margin rows with no pass at all, but after the margin stopped asking for a pass on every render (#5308), three sources still ran the whole pass on these inputs. On the `asks` page each pass seats every row: - Heading links name a heading as an anchor the first time the pointer reaches it, by writing `anchor-name` into its `style`. A wheel step that brings a heading under the pointer, or a hover, ran a pass. - Command hints write a key into the seat a widget lends them beside each control (`.lf-binding-seat`) and show or hide it. Each Tab ran a pass. - Text written into a margin control's label, which stands over the row, ran one too (review of #5308, item 2). A keystroke ran none, but each batch of mutations in the chrome, such as the panel's field redrawing, climbed from every row's target to see whether it had moved. Each source now asks only where its change can move a seat: - The page observer reads each `style` change against its old value (`attributeOldValue`) and ignores one that changes only anchor names. A name another box positions itself by moves nothing. This also covers the anchors the margin's own carriers name. - Leaf's own surfaces in the page, the chrome and the lent key seats, which take no part in flow (surfaces.css), are no page content. The page observer ignores their changes, and a pin no longer reads them as cover. A widget lends each key the seat of the control it names, such as an option's mark (options.css), which a pin already keeps clear of, so no pin stood over a key before or after. Read as cover, though, a key shown on a focus move ran a pass that moved every pin beside the options by 2 to 3 pixels, and the key leaving ran another that moved them back (Chromium and Firefox). Now they stay. - In a row, children added or removed ask for a pass. Text and attributes ask only where the row no longer has the size it was seated at. A control's label is placed by its own pass (`placeMarginEntryLabel`) and asks for none. - The moved-node climb reads only the page's own mutations. Margin layout passes counted in one probe journey on the `asks` page at 512 sections, main → this, where each pass seats every row (about 100 ms here): | input | main | this | |---|---|---| | 10 wheel steps | 1 | 0 | | 10 hovers over headings | 4 | 0 | | 6 Tabs | 3 | 0 | | 10 keystrokes in the panel's field | 0 | 0 | A full pass at 512 sections costs about 124 ms of main-thread time (the minimum of 12, at load 45). With main and this branch open side by side and measured in alternation at load 57 to 82, a click on an option at 512 went from 605 to 473 ms and a Tab from 419 to 375 ms (minimums of 6 and 18). A click moves focus, which lends key hints too. On this host the per-input times swing by half between runs, so the passes saved are the firmer measure. Every row's place, coordinates and withheld state still equal main's at every step of journeys on six pages, since each pass still seats every row.
In a profile of one full margin pass on the `asks` page at 512 sections, three quarters of the time goes to `coverIn`, the room each pin keeps clear of, and most of the rest to reading every row's target. Two reads in it repeated work that one read answers: - `targetShown` read each pin's drawn target parts and clip twice, once to read the row and again to check its seat. The row's reading now keeps what the target's scrollers leave of the window (`targetView`), and the seat is checked against that (`shownWithin`). - The children index climbed every child's ancestors looking for a Leaf surface (`closest`). The walk reaches what a surface holds only through the surface itself, so asking the child (`matches`) gives the same answer. A per-pass memo of each clip walk was also tried and dropped. Counted in one pass, 9,216 of its 10,752 walks were for distinct items, so a memo spares at most one walk in seven, and it measured no faster. Measured on one host with both arms open and alternating at load 45 to 50, a full pass at 512 sections went from 131 to 124 ms (minimum of 12) and from 204 to 193 ms (median). Every row's seat equals main's at every step of journeys on six pages.
A widget lends each option's key the seat of the option's own mark (options.css), and a pin keeps clear of the mark as a control, so no pin stands over a shown key. Since the previous commit, a pass no longer reads a key as cover. The keys showing as focus enters the options leave every pin where it stood, where before they moved each pin beside the options by 2 to 3 pixels and back as focus left. The test focuses an option with a pin by each card, forces a full pass, and checks that every pin stands where it did before the keys showed, and over none of them. On main's margin layout it fails: the pins move 3 pixels. Stacking keys above pins in CSS was the alternative considered. A lent key is page content, and the stacking ladder in tokens.css keeps every page box below the chrome the pins stand in, so no z-index on the key can reach them. Since no pin covers a key, nothing needs to.
`nameMarkers` sorted the margin's hosts by searching the inventory for each one's entry inside the sort's comparator, then searched again for each host's spoken position: a walk over the inventory for each comparison, so a render grew with n² log n in the page's entries. It now reads every entry's place into a map once. At 512 sections the comparator took 0.3 ms of a click (profiled), so the saving there is small; the change is to the growth. Most of the 17 ms `nameMarkers` takes per click at 512 is `paintMarker` naming every marker again, which this leaves as it is.
…d change The margin's page observer asks for a full pass on every change to a page box's style, class, `hidden` or `open`, since any of them can move what a seat reads. Some of those writes are the runtime's own paint, which changes how a box looks and moves none: the anchor name the runtime gives a heading the pointer reaches, or a box a row or a chip stands by, and the outline class a mark draws, such as `.lf-traced` while the pointer is on a margin entry. An earlier commit on this branch stopped the anchor names asking for a pass by ignoring any change that only named an anchor. That also ignored an author's anchor name, which can move a box positioned by it, such as a button carried onto a pin. Hovering a margin entry still asked for a pass for its trace. The rule now has one home. The runtime's paint goes through `paint` (page-paint.js), which hands each observer that reads layout from mutations (`readsLayout`) what it heard before the write, writes, and drops what the write produced, as the pass drops its own writes to its rows. `nameAnchor` and the marks in target-paint.js write through it. The margin's page observer is one observer on every tree it hears, registered there, and hears every authored change again, anchor names included. A scroll of the document carries every row but a withheld one, so the stir reading now reads only the withheld rows, which the margin keeps where it withholds them. Before, it read every row's anchor and passage and climbed its ancestry first: 512 anchor reads and 1,024 ancestor steps a frame at 512 rows, for no pass. The rows it reads, and what it asks of them, are unchanged. Behavior: - A control an authored anchor name moves into a pin's seat moves the pin, as on main. The new test fails without this change: the pin stays under the button. - Hovering a margin entry runs no pass: 6 hovers over the markers on the `asks` page at 512 sections ran 3 full passes on main (#5308), and run none now. Wheel steps, heading hovers, Tabs and keystrokes stay at none.
… can reveal `paint` dropped every record its write produced. That included any change the page's own code made in reaction to the write: a custom element that moves a button when its class changes, for instance when a margin entry's trace adds `.lf-traced` to it, moved the button unheard, even in another shadow tree. Each paint now says what it changes: a token of a token list, such as a class or an anchor part, or a property of `style`, such as `anchor-name`. After the write, `paint` hands each observer that reads layout every record whose attribute changed by anything else, which the record's old value shows: its value before, against the next record's or the attribute's value now. So such an observer observes old values again, as the margin's page observer does. The document scroll's reading kept every withheld row, including rows whose targets stand in a closed disclosure or a tab not chosen, and read their passages and extents on every scroll though a scroll can draw none of them. It now keeps only the withheld rows whose targets are drawn. Revealing a skipped target brings its own pass. `tests/runtime/page-paint.test.mjs` holds both cases of the first: a custom element's reaction in another shadow tree, and an author's restyle in the same write as an anchor name. Both fail against the previous `paint`.
… don't listen The two commits before this one kept the runtime's own writes to page boxes from asking for a margin pass by filtering the observer's records: `paint` dropped a record whose change matched what the write meant to change, a class token or a style property. A value cannot say who changed it. A page's own code reacting at once to the runtime's write, by changing the same property on another box or rewriting a class with a no-break space between its words, had its change dropped too, and a button it moved onto a pin went unheard. The runtime now writes its paint where the margin's observer does not listen: - The aim, the trace a margin entry draws on what it concerns, the proxy ring and the location ring are attributes (`data-lf-aimed`, `data-lf-traced`, `data-lf-proxied`, `data-lf-projected-location`) among the runtime's other paint attributes (page-paint.js), and the theme selects them (surfaces.css). Nothing but the runtime, the theme, one developer state and the tests read the classes they replace. - A box in the document that the author names nowhere is named by a rule in the runtime's own sheet, keyed by `data-lf-anchor`, as a box in a widget's shadow tree is already named by a `::part` rule in that sheet. The rule is important, as the inline name was over the page's stylesheets. A box the author names keeps both names inline, since a rule would replace the author's; the margin hears that write and runs one pass when the name is first given. An inline name the author writes later moves the box to the inline path. - `paint`, its record filter and `readsLayout` are gone, and the margin's page observer reads no old values. Every change to a page box's class, style, `hidden` or `open` asks for a pass. Design mode's legend ignores the mark attributes, as it ignored the mark classes. The render gate's picture finds the box an ink is anchored to by `data-lf-anchor`, or inline where the author names it too. A document scroll now reads again every withheld row whose target a scroll can bring back: any `checkVisibility` counts as drawn, which includes content the browser skips until it nears the window (`content-visibility: auto`). The previous commit left those out, so a row in a section of fixed height stayed withheld once the page scrolled to it. Rows whose targets left the page, or stand in a closed disclosure, a tab not chosen or a hidden box, stay out; what reveals one brings its own pass. Tests: - `test_a_page_s_reaction_to_a_runtime_mark_moves_a_pin_clear` has a custom element move a button onto a pin when the trace marks it: by a restyle, by a class a no-break space joins, and by an anchor name handed to a box on the pin. The pin moves clear each time. - `test_a_row_in_content_skipped_until_near_stands_once_the_page_scrolls_to_it` fails on the previous commit and passes here and on main. - `tests/runtime/page-paint.test.mjs` goes with `paint`. Tests read the marks as attributes.
…n a document scroll The previous commit named a document box by a rule in the runtime's own sheet. Those rules stayed for the page's life, one per name ever given, and the browser matches a box against every rule keyed by the same attribute, so their cost grew with the names given rather than the boxes named. Naming anchors at a bounded cost is a change of its own. Anchor names go back to main's inline write, which the margin hears: a heading the pointer first reaches, or one a wheel step brings under it, runs a pass again, as on main. The marks stay attributes. The document scroll's reading keeps every withheld row again, as it did before the last two commits narrowed it. A row a scroll can bring back is not one the runtime can tell from its target alone: `checkVisibility` is false for a `display: contents` target with no box, in a section the browser skips until it nears the window, and its row stayed withheld. The rows the reading reads, and the checks it makes of them, are main's, less the ordinary rows the document carries. The content-visibility test passes, as do the authored anchor and reaction tests, the reaction test's anchor name now an author's inline write the margin hears.
# Conflicts: # browser/runtime/chrome.css
leaf-agent
previously approved these changes
Nov 4, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
The description quotes root AGENTS.md, "Responsiveness", as saying a pass's work "runs only for the change that makes it necessary, which its owner records when the change happens". That sentence isn't in AGENTS.md, or anywhere else in the tree. The squash merge makes this description main's commit message, so please replace the quote before landing. The section's actual rule covers the change: "The work an input does, such as a keystroke, a click or a wheel step, depends on what the input changes, and never grows faster than the page."
leaf-agent
approved these changes
Nov 4, 2026
This was referenced Nov 5, 2026
leaf-agent
added a commit
that referenced
this pull request
Nov 5, 2026
`test_a_wait_takes_the_suites_deadline` refuses a literal timeout anywhere in the suite. A deadline sized to the author's machine fails a correct product on a busy runner (`tests/AGENTS.md`, "Functional results do not depend on execution speed"). It has failed in the last two scheduled runs and on current main because of seven new literal timeouts: - #5359: the two pin-clearance `wait_for_function` calls in `tests/browser/margin/test_pins.py`, plus Copy's `click` and the `lf-withheld` expectation in `tests/browser/margin/test_scrollers.py` (`timeout=5000`) - #5399: the motion study's shared-clock wait in `tests/browser/widgets/test_motion.py` (`timeout=10_000`) - #5371: the two closed-tab `data-lf-source` expectations in `tests/browser/widgets/test_code_and_documents.py` (`timeout=15_000`) None of these waits measures how long its subject takes, so each now takes `SERVED_TIMEOUT_MS`, the default that `render_harness` gives every wait that names none. The lint test fails on main `e0c0f9c5f` and passes with this change. These tests also pass with it: `test_a_control_an_authored_anchor_name_moves_into_a_pin_s_seat_moves_the_pin`, `test_a_page_s_reaction_to_a_runtime_mark_moves_a_pin_clear`, `test_a_pin_on_a_code_block_s_first_line_leaves_copy_pressable`, `test_a_row_in_content_skipped_until_near_stands_once_the_page_scrolls_to_it`, `test_recordings_a_revision_adds_join_the_studys_clock` and `test_a_tab_opened_while_closed_documents_draw_reports_its_document_at_once`. `test_a_comment_on_a_closed_tab_s_document_never_reads_as_earlier_data` fails with and without this change: its thread quote is never found, the same failure as in push run [41976158322](https://github.com/max-sixty/leaf/actions/runs/41976158322). Refs #4225 — automated triage Co-authored-by: leaf-agent <[email protected]>
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.
After #5308, a margin render no longer asks for a layout pass, but a hover over a margin entry and a Tab still ran the whole pass, which seats every row. On the
askspage at 512 sections a pass costs about 124 ms of main-thread time. The requests came from writes the runtime makes to page elements to paint them: the outline a margin entry's hover draws on its target, and the keys command hints show inside a widget. Neither moves a box a seat reads.This applies the rule in root
AGENTS.md, "Responsiveness": work a pass would redo for the whole page "runs only for the change that makes it necessary, which its owner records when the change happens".What changes
The runtime's marks stand where the margin's observer does not listen. The aim, the trace a margin entry draws on its target, the proxy ring and the location ring are attributes (
data-lf-aimed,data-lf-traced,data-lf-proxied,data-lf-projected-location) among the runtime's other paint attributes (page-paint.js), rather than classes, and the theme selects them (surfaces.css). The margin's page observer hears every change to a page box's class, style,hiddenoropen, an author's included, as on main. Design mode's legend ignores the mark attributes, as it ignored the classes they replace.The anchor names the runtime writes inline into a box's style are still heard: a heading the pointer first reaches runs a pass, as on main. Naming anchors without that pass, at a cost bounded by the boxes named, is a change of its own.
Leaf's own surfaces are no page content. The page observer ignores changes inside the chrome and inside the seats command hints lend a widget for its keys (
.lf-binding-seat). The pass's index of what a pin keeps clear of skips them too. A widget lends each key the box of the control it names, such as an option's mark or the Add button, and a pin already keeps clear of controls, so no pin stood over a key before this change or after it. Read as cover, though, a key showing on a focus move ran a pass that moved every pin beside the options by 2 to 3 pixels, and moved them back when focus left. Now the pins stay where they are. Checked in Chromium and Firefox.A row's face asks only when its size could change. An element added to or removed from a row asks for a pass. Text or an attribute changed in a row asks only where the row no longer measures the size the last pass seated it at. A control's label stands over the row, placed by its own pass, and asks for none.
A document scroll reads only the withheld rows. The document carries every other row with its target, so the scroll reading now reads only the withheld rows, which the margin keeps where it withholds them. Before, it took every row's anchor and passage and climbed its ancestry, then skipped all but the withheld rows. The rows it reads, and the checks it makes of them, are unchanged.
A full pass reads each row's view of its target once, keeping it on the row's reading for the seat check, and its index of children asks each child whether it is a Leaf surface instead of climbing its ancestors. Naming the markers reads each entry's place in the inventory from a map built once, instead of searching the inventory inside the sort's comparator.
Evidence
Margin layout passes counted in one probe journey on the
askspage at 512 sections. Main is ecf4dc1, with #5308.The wheel steps and heading hovers run passes on both arms when a heading first takes the anchor name its link stands by.
Reading each row's view of its target once took one full pass at 512 sections from 131 to 124 ms (minimum of 12, with both arms open and measured in alternation). Measured the same way against main at a host load of 57 to 82, on the branch's first two commits, a click on an option at 512 sections went from 605 to 473 ms and a Tab from 419 to 375 ms (minimums). On this host per-input times swing by half between runs, so the pass counts are the firmer measure.
Checks
leaf-dev probe --base: 43 steps in all, covering load, content inserted, shrunk and removed above every row, a target growing a line, a resize round trip, and stacked rail rows whose targets are hidden and shown with and without the pointer holding a row. Pages: a 64-sectionaskspage, a 24-section threads page, a page of stacked rail threads,ship-review,review-a-planandlog-retention.test_a_control_an_authored_anchor_name_moves_into_a_pin_s_seat_moves_the_pinhands an anchor name between two boxes of the same size, which carries a button onto a pin, and the pin moves clear.test_a_page_s_reaction_to_a_runtime_mark_moves_a_pin_clearhas a custom element move a button onto a pin in the same task the margin's trace marks it: by a restyle, by a class whose words a no-break space runs together, and by an anchor name handed to a box on the pin. The pin moves clear each time.test_a_row_in_content_skipped_until_near_stands_once_the_page_scrolls_to_itscrolls a section of fixed height withcontent-visibility: autointo the window, and its row stands.test_an_option_s_key_moves_no_pin_and_stands_under_noneshows the keys with a pin by each option card and forces a pass. It fails on main, where the pins move 3 pixels, and passes on this branch.test_an_aimed_comment_keeps_its_place_with_on_me_open(both widths),test_a_heading_copies_the_link_to_the_section_it_opens, and, in three runs of four on each,test_a_commented_block_says_so_to_a_screen_user.pnpm run test:runtimepasses 776 tests, and the browser type check passes.