Skip to content

Arm the page and open the target picker without restyling or laying out what it holds - #6037

Merged
max-sixty merged 3 commits into
mainfrom
grind/arming-restyle
Nov 15, 2026
Merged

max-sixty merged 3 commits into
mainfrom
grind/arming-restyle

Conversation

@max-sixty

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

Copy link
Copy Markdown
Owner

On #4781's page (30 tabs, each an lf-text-document of about 4 MB), each press or
release of ⌥ held Firefox's main thread 1.0–1.6 s on a quiet host, and the target
picker's first open 7–15 s. Now ⌥ takes about 100 ms and the picker's first open
about 200 ms. In Chromium ⌥ went from 34–54 ms to 5–14 ms. Chromium's first picker
open on main had not finished after 10 minutes on that page, its renderer at 11.5 GB;
on this branch it took 107–113 ms. On a page of ten 1 MB documents it went from 4.1 s
to 29 ms.

Causes

Firefox's profiler names three, each a Styles or flush marker whose cause stack is a
runtime write or read:

  • The armed arrow. body:is([data-lf-aiming], [data-lf-design-mode]) { cursor: default } (chrome.css) changed an inherited property on body, so each arm change
    restyled 2,364,661 elements, 1.0–1.2 s.
  • The aim's veil. The aim box declares --lf-aim-veil on the item it boxes
    (surfaces.css). Unregistered, it inherits, so boxing a text document restyled its
    152,148 elements, 370 ms. The mark properties beside it are registered
    non-inheriting already (base.css).
  • The picker's first map. visibleTargets asks visibleTargetParts of every
    target. A closed tab's until-found panel keeps a box of no area, so shownParts
    went on to the panel's children and read their boxes, and each read laid out that
    tab's document: about 270 ms, 29 times. visibleTargetParts already answered a
    target inside skipped content without a geometry read, but not a drawn target whose
    children are skipped.

Change

  • The armed arrow is gone. While armed, the hand still stands on the element under
    the pointer where a press takes an item, and elsewhere the page keeps its own cursor.
    Over a gap that is the arrow, as before. Over words no item holds, and over editable
    content (contenteditable) no item holds, it is now the I-beam where main drew the
    arrow, though a press there still takes nothing. Those words are 115 of the 10,213 in
    examples/ (1.1%), mostly each page's h1 and the label line above it (count of
    authored words with no ancestor carrying an id). This is a
    call Max may reverse. This branch's first commit, 47858ea, keeps the arrow by
    standing it on the element under the pointer through a paint attribute of its own
    (data-lf-armed-arrow, about 45 lines); the review found that WebKit then drew the
    arrow over links and text fields, whose cursor: auto its UA sheet states, and fixed
    it by leaving controls out of the arrow (!closestAcross(under, WORKS) in
    paintArmedCursor).
  • --lf-aim-veil is registered non-inheriting, with the other mark properties.
  • shownParts(el, {leaveSkipped: true}) leaves out children the browser skips
    (skipped), and visibleTargetParts asks for it. Outline marks still read skipped
    content and pay, as skipped's header says they should. visibleTargetParts also
    serves the margin (margin-layout.js), the floating comment box (floating.js),
    comment placement (comment-placement.js) and thread destinations
    (thread/destination.js). On a page with commented boxes in an until-found panel,
    in an off-screen content-visibility: auto box and in an auto box inside a box of no
    area, the margin's rows matched main at three scroll positions in Chromium and Firefox.
  • A mouse leaving the window takes the hand and the aim's box with it while the key
    is still down (aim.js, pointerOut). Before, both stayed standing until the
    pointer came back or the key came up.

What the user sees

The computed cursor at the pointer matches main in Chromium, Firefox and WebKit, in 6
states (rest, ⌥, after ⌥, picker, Design mode, after Design mode), over: items' words
and emphasis, links in and outside an item, a button, text field, textarea, select,
label, checkbox, words in a cursor: grab box, a summary, an lf-diff shadow stage's
item and an lf-option. Where a press takes nothing it differs as described above:
words no item holds (a heading, prose, emphasis, code, a page script's own shadow
root) and editable content no item holds read auto, drawn as the I-beam, where main
read default, drawn as the arrow; gaps read auto too, and both draw the arrow
there. Stills of review-a-plan at rest, under ⌥, in the picker, in Design mode
and after it are pixel-identical to main in Chromium, Firefox and WebKit.

Measurements

#4781's page built by a script (30 tabs in lf-tabs list="side", each lf-text-document
bound to its own source of 4 MB of lines of 6–12 words), served by leaf server run --lifetime temporary with a throwaway state home; main at 28c1812 as a build_arm
snapshot against the branch, a fresh load per arm and round, arms alternating, the
pointer resting over the open document. The longest task is the longest gap in a chain
of zero timeouts within 2–3 s of the key. Chromium 158 headless and Firefox 159 through
Playwright, 1440×900. Milliseconds, one value per press.

Firefox, main Firefox, branch Chromium, main Chromium, branch
⌥ down 1,488, 1,508, 4,672, 4,014 129, 125, 108, 103 50, 46, 54, 48 12, 6, 6, 6
⌥ up 1,065, 1,077, 4,557, 5,090 117, 107, 102, 113 34, 34, 35, 35 6, 6, 6, 5
Picker, first open 7,398, 15,096 202, 213 not done after 10 min 113
Picker, second open 1,525, 1,565 139, 139 58
Picker close 1,215, 1,225 286, 222 119
Elements one ⌥ restyles 2,364,661 + 152,148 3–5 2,973 18–19

Those rounds ran with the arrow standing on the element under the pointer, the version
before this one. Without it, one load at load 4–5 read Firefox ⌥ 97–105, picker 172
and 191; Chromium ⌥ 6–14, picker 107 and 54. Firefox rows are rounds at load 11–25;
one earlier round at load 28–32 read 4.1–7.4 s on main against 0.36–1.6 s on the
branch. Firefox's element counts are from its profiler (elementsStyled), Chromium's
from its trace (UpdateLayoutTree).

Left as it was

  • Firefox still walks the page when the arm changes. Three rules read the arm on
    body through a descendant combinator: the item hand (chrome.css), and the hand
    over a mark and over a commented element at rest (annotation-chrome.css). Firefox
    visits every element to invalidate them and restyles none, 85–150 ms on Export: an exported page parses every data source before its first draw #4781's page,
    most of what ⌥ still costs. With the three rewritten without the attribute (an
    experiment, not on this branch), ⌥ took 23–39 ms. Dropping the condition changes
    which cursor wins while armed over a drafted comment's element and over a control
    inside a commented element, so it is a change of look to weigh on its own.
  • Design mode's first entry in Chromium on Export: an exported page parses every data source before its first draw #4781's page had not finished after
    9 minutes on main (not measured on this branch). paintLegend (design.js) reads
    getComputedStyle(addressable).borderRadius and checkVisibility() without
    contentVisibilityAuto for every addressable, those in closed tabs included; I expect
    that is the cost, unverified.

Tests

  • test_arming_the_page_restyles_only_what_the_pointer_is_over (Chromium): with the
    pointer over an item of 600 paragraphs, ⌥ down and up, picker open and close, and
    Design mode in and out each restyle under a quarter of a whole-page restyle (1–32 of
    690 here). On main every move restyled 604–611; with only the veil reverted, 601–608.
  • test_the_target_picker_reads_no_box_in_a_closed_tab: opening the picker reads no
    box inside a closed tab's panel, and the tab's words take a hint once it opens. On
    main the map read the closed paragraph's box.
  • test_the_armed_page_promises_only_what_a_press_would_take: beside the column, where
    a press takes nothing, the armed cursor reads auto; a new case leaves the window
    with ⌥ held and expects the box and the hand gone, which fails on main.

Ran 256 browser tests, 252 passed: the new ones and every test that reads a cursor, the
arm attributes, ⌥, Design mode or the picker, or opens closed tabs, hints or skipped
content. Four failed: test_a_focused_thread_covers_the_pages_choice_hints and
test_a_control_a_widget_built_is_told_from_a_label_it_wrote fail the same way on main;
test_contextual_messages_share_text_spacing_through_send_and_reopen (both params)
misses by a fraction of a pixel and fails on main too (1 of 6 runs there), and passed 2
of 3 alone here. Also pnpm run test:runtime (978 passed), pnpm run check:browser
and pre-commit on the changed files. Not run: the whole suite, journeys, a restyle
count in Firefox (the restyle tests read Chromium's trace), and WebKit's timings.

Part of #5194.

…ut what it holds

On #4781's page (30 tabs, each an `lf-text-document` of about 4 MB), each press or
release of ⌥ held Firefox's main thread 1.0–1.6 s on a quiet host, and the target
picker's first open 7–15 s. Now ⌥ takes 100–130 ms and the picker's first open about
200 ms. In Chromium ⌥ went from 34–54 ms to 5–12 ms. Chromium's first picker open on
main had not finished after 10 minutes on that page, its renderer at 11.5 GB; on this
branch it took 113 ms. On a page of ten 1 MB documents it went from 4.1 s to 29 ms.

## Causes

Firefox's profiler names three, each a `Styles` or flush marker whose cause stack is a
runtime write or read:

- **The armed arrow.** `body:is([data-lf-aiming], [data-lf-design-mode]) { cursor:
  default }` (`chrome.css`) changed an inherited property on `body`, so each arm change
  restyled 2,364,661 elements, 1.0–1.2 s.
- **The aim's veil.** The aim box declares `--lf-aim-veil` on the item it boxes
  (`surfaces.css`). Unregistered, it inherits, so boxing a text document restyled its
  152,148 elements, 370 ms. The mark properties beside it are registered
  non-inheriting already (`base.css`).
- **The picker's first map.** `visibleTargets` asks `visibleTargetParts` of every
  target. A closed tab's until-found panel keeps a box of no area, so `shownParts`
  went on to the panel's children and read their boxes, and each read laid out that
  tab's document: about 270 ms, 29 times. `visibleTargetParts` already answered a
  target inside skipped content without a geometry read, but not a drawn target whose
  children are skipped.

## Change

- **The arrow stands on the element under the pointer**, as the item hand already did
  (`page-geometry.js`, `paintArmedCursor`; `marks.css`, `[data-lf-armed-arrow]`). It
  goes on the innermost element, through declared shadow stages, which adopt
  `marks.css`. It goes there only where that element's computed cursor is `auto`,
  which is where the inherited arrow reached, and only where the pointer is over the
  element's own words (the caret position at the point) or in editable content. Those
  are the only places `auto` draws anything but the arrow; over the gap between two
  blocks it draws the arrow already, and an arrow on the element holding both would
  restyle all it holds at each crossing. The rule sits in the lowest layer, so a cursor
  any page or Leaf rule states still wins.
- **`--lf-aim-veil` is registered non-inheriting**, with the other mark properties.
- **`shownParts(el, {leaveSkipped: true})`** leaves out children the browser skips
  (`skipped`), and `visibleTargetParts` asks for it. Outline marks still read skipped
  content and pay, as `skipped`'s header says they should.

## What the user sees

The computed cursor at the pointer matches main for 24 kinds of content in 6 states
(rest, ⌥, after ⌥, picker, Design mode, after Design mode), in Chromium and Firefox:
prose inside and outside an item, links, emphasis, a button, text field, textarea,
select, label, checkbox, contenteditable, words in a `cursor: grab` box, code, a
summary, words in an `lf-diff` shadow stage and in a page script's own shadow root,
an `lf-option`, and gaps. The one difference is the gap between two blocks, where main
computed `default` and this branch `auto`; both engines draw the arrow for `auto` over
an element that is neither text nor editable (Blink `EventHandler::SelectAutoCursor`,
Gecko `nsIFrame::GetCursor`). Stills of review-a-plan at rest, under ⌥, in the picker,
in Design mode and after it are pixel-identical to main in both engines.

## Measurements

#4781's page built by a script (30 tabs in `lf-tabs list="side"`, each `lf-text-document`
bound to its own source of 4 MB of lines of 6–12 words), served by `leaf server run
--lifetime temporary` with a throwaway state home; main at 28c1812 as a `build_arm`
snapshot against this branch, a fresh load per arm and round, arms alternating, the
pointer resting over the open document. The longest task is the longest gap in a chain
of zero timeouts within 2–3 s of the key. Chromium 158 headless and Firefox 159 through
Playwright, 1440×900. Milliseconds, one value per press.

| | Firefox, main | Firefox, branch | Chromium, main | Chromium, branch |
|---|---|---|---|---|
| ⌥ down | 1,488, 1,508, 4,672, 4,014 | 129, 125, 108, 103 | 50, 46, 54, 48 | 12, 6, 6, 6 |
| ⌥ up | 1,065, 1,077, 4,557, 5,090 | 117, 107, 102, 113 | 34, 34, 35, 35 | 6, 6, 6, 5 |
| Picker, first open | 7,398, 15,096 | 202, 213 | not done after 10 min | 113 |
| Picker, second open | 1,525, 1,565 | 139, 139 | | 58 |
| Picker close | 1,215, 1,225 | 286, 222 | | 119 |
| Elements one ⌥ restyles | 2,364,661 + 152,148 | 3–5 | 2,973 | 18–19 |

Firefox rows are rounds at load 11–25; one earlier round at load 28–32 read 4.1–7.4 s
on main against 0.36–1.6 s here. Firefox's element counts are from its profiler
(`elementsStyled`), Chromium's from its trace (`UpdateLayoutTree`).

## Left as it was

- **Firefox still walks the page when the arm changes.** Three rules read the arm on
  `body` through a descendant combinator: the item hand (`chrome.css`), and the hand
  over a mark and over a commented element at rest (`annotation-chrome.css`). Firefox
  visits every element to invalidate them and restyles none, 85–150 ms on #4781's page,
  most of what ⌥ still costs. With the three rewritten without the attribute (an
  experiment, not on this branch), ⌥ took 23–39 ms. Dropping the condition changes
  which cursor wins while armed over a drafted comment's element and over a control
  inside a commented element, so it is a change of look to weigh on its own.
- **Moving onto new words in Chromium.** Chromium picks the cursor before the
  pointermove listener runs (`EventHandler::HandleMouseMoveOrLeaveEvent`) and picks up
  the arrow at its next cursor update, at most 20 ms later (`kCursorUpdateInterval`).
  So moving onto new words while armed can show the I-beam for up to 20 ms, where main's
  arrow was already in place; the item hand has had the same lag on main. In Firefox
  the listener's `getComputedStyle` brings the mark into style before the mouse
  event's own cursor update, so I expect no gap there. Read from both engines' source;
  headless browsers draw no cursor to observe.
- **Design mode's first entry in Chromium** on #4781's page had not finished after
  9 minutes on main (not measured on this branch). `paintLegend` (`design.js`) reads
  `getComputedStyle(addressable).borderRadius` and `checkVisibility()` without
  `contentVisibilityAuto` for every addressable, those in closed tabs included; I expect
  that is the cost, unverified.

## Tests

- `test_arming_the_page_restyles_only_what_the_pointer_is_over` (Chromium): ⌥ down and
  up, picker open and close, Design mode in and out over words no item holds, and ⌥
  over an item of 600 paragraphs, each restyle under a quarter of a whole-page restyle.
  On main every move restyled 604–611 of 690; with only the veil reverted, ⌥ over the
  item restyled 601.
- `test_the_target_picker_reads_no_box_in_a_closed_tab`: opening the picker reads no
  box inside a closed tab's panel, and the tab's words take a hint once it opens. On
  main the map read the closed paragraph's box.
- `test_the_armed_page_promises_only_what_a_press_would_take`: beside the column, where
  no words stand, the armed cursor now reads `auto` or `default` rather than `default`.

Ran 256 browser tests, 252 passed: the new ones and every test that reads a cursor, the
arm attributes, ⌥, Design mode or the picker, or opens closed tabs, hints or skipped
content. Four failed: `test_a_focused_thread_covers_the_pages_choice_hints` and
`test_a_control_a_widget_built_is_told_from_a_label_it_wrote` fail the same way on main;
`test_contextual_messages_share_text_spacing_through_send_and_reopen[touch]` flakes on
main too (1 of 6 runs); `test_g_hints_press_each_visible_page_map_margin_entry` failed
once under `-n 4` and passed 5 times alone. Also `pnpm run test:runtime` (978 passed),
`pnpm run check:browser` and pre-commit on the changed files. Not run: the whole suite,
journeys, WebKit, and a restyle count in Firefox (the restyle tests read Chromium's
trace).

## Calls to review

- The arrow is stated only over words and editable content, so a gap between blocks
  computes `auto`, which draws the same arrow.
- The veil's registration rides along: it is the same kind of restyle, on the same
  gesture, and measured.

Part of #5194.
…e leaves the window

The arrow stood on the element under the pointer over words no item holds. In WebKit it
replaced the cursor links and text fields keep while armed: WebKit's UA sheet states
`cursor: auto` on them, which the arrow's guard read as the body's inherited arrow, and
the arrow's rule outranks the UA sheet. Rather than add a case for controls, the arrow
goes, with its paint attribute (`data-lf-armed-arrow`), its rule in marks.css and
`wordsAt`. While armed, words no item holds now show the page's own I-beam, though a
press there takes nothing: 115 of the 10,213 authored words in `examples/`, mostly each
page's `h1` and the label line above it. Gaps draw the arrow as before. The computed
cursor at the pointer matches main in Chromium, Firefox and WebKit over links, fields,
controls, items, a `cursor: grab` box and a shadow stage's item, in rest, ⌥, picker and
Design mode states.

A mouse that leaves the window with ⌥ held stood the hand and the aim's box over the
item it left until the pointer came back. `aim.js` now refreshes the aim on the
`pointerout` that has nothing to relate to, after the shared recorder has forgotten the
position (pointer.js).

Tests: `test_arming_the_page_restyles_only_what_the_pointer_is_over` now arms over an
item, where the hand and the box stand (1–32 of 690 elements restyled; 604–611 on main,
601–608 with the veil reverted); `test_the_armed_page_promises_only_what_a_press_would_take`
reads `auto` beside the column and gains a case leaving the window, which fails on main.
Two comments still described the arrow the previous commit removed. aim.js said the
cursor already told the user a press takes nothing everywhere outside the chrome; over
words no item holds, and over content the user edits, it is now the page's own I-beam.
annotation-chrome.css named "the armed arrow" for the default cursor a chrome mark
draws while the page is armed.
@max-sixty
max-sixty marked this pull request as ready for review November 15, 2026 10:44
@max-sixty
max-sixty merged commit 0144d46 into main Nov 15, 2026
6 checks passed
@max-sixty
max-sixty deleted the grind/arming-restyle branch November 15, 2026 10:59
max-sixty added a commit that referenced this pull request Nov 17, 2026
…⌥ without restyling it in Firefox (#6227)

On #4781's page, a side list of tabs holding thirty large text
documents, three
gestures still cost what the page holds:

- **A Tab in the target picker onto a side tab**, in Design mode, and
**a Design mode
press on a side tab**. Each named the tab by asking whether another
control in its
owner, the tabs widget, shares its name, and `namedParts` answered with
a query of
everything the widget holds, every tab's document included. A CPU
profile of a
  picker Tab onto a side tab on `documents` at 256 put 17.8 of its ms in
`namedParts`, 16.6 of them in `querySelectorAll`. A press spent 17.5 ms
there.
- **Holding ⌥ in Firefox.** The arm was an attribute on `body`, and four
cursor rules
read it through a descendant combinator, so each ⌥ down and each ⌥ up
made Firefox
walk every element of the page. A Gecko profile shows a style flush of
about 55 ms
that restyled 0 to 14 elements. With the four rules deleted, the gesture
fell from
  62–70 ms to 11–14 ms.

## Change

- `namedParts` (anchor-resolution.js) walks down the owner's own tree
and the declared
roots in it, and steps over each addressable it meets, with everything
that
addressable holds. The controls it skips belong to those addressables,
so the result
is the set the old filter on `addressableAt` kept, and naming a part
costs what its
owner holds as its own. The picker's announcement and the press share
this capture
(`captured`), so one change fixes both. Counting names once per picker
inventory
  would have fixed only the picker.
- The hand over a mark comes only from `[data-lf-over-mark]`, which
`anchor-paint.js`
paints from the same hit test a press uses (`markAt` is `markHit`). That
hit test
leaves out controls, the chrome and hidden annotations. `.lf-mark-el {
cursor:
pointer }` repeated it for whole marked elements, and four rules undid
it again: on
a drafted element, with the annotations hidden, in the chrome's
`@scope`, and in the
chrome while armed. All five are gone, and with them every rule that
read the arm
  or Design mode from `body`.
- `aim.js` no longer writes `data-lf-aiming` on `body`, and the paint
vocabulary loses
it. `design.js` no longer writes `data-lf-design-mode` there, whose only
readers were
tests. A `body[…] …` rule on either would make Firefox walk the page
again, and the
restyle-count guard reads only Chromium's trace, so the tests now wait
for Design
  mode's legend (`expect_design_mode`, render_harness.py).
- The aim's hand is `body [data-lf-over-item] { cursor: pointer
!important; }`, as the
crosshair, its sibling paint from the same writer, is. Only an armed
page or Design
mode paints it, and where the aim's press takes an item the hand covers
whatever
  cursor the page gives that item.
- `leaf-dev bench` gains three inputs. `aim` holds ⌥ down and lets it
up, the pointer
resting on the page's content. `pick`, in Design mode, walks the picker
up from the
last hint in view and back; on `documents` those hints are the side
list's last tabs.
`part` is a Design mode press on the first side tab, its empty comment
closed after.
  The daily `documents` run reads `pick` and `part`.

## Calls Max may reverse

Four cursors change, each to match what a press there does:

- **A tab stop or other control inside a marked item reads `auto` at
rest**, where it
read `pointer`. A press there focuses or works the control and opens no
thread
(`markAt` leaves out controls), so the hand promised a press nothing
takes.
- **A mark in the chrome reads `auto` under ⌥**, where it read
`default`. The aim never
takes anything in the chrome, so it keeps the same cursor the rest of
the armed page
  has shown since #6037, where a press takes nothing.
- **A mark in the chrome reads `auto` in Design mode**, where it read
`default`. Design
mode leaves the chrome working as it does outside the mode, so a press
there is the
chrome's own, and the mark keeps the cursor it has at rest. The rule
that drew the
arrow read `body[data-lf-design-mode]`, the Firefox walk this change
removes.
- **The aim's hand covers a cursor the page gives an item**, at any
weight. On main a
page rule heavier than the hand's 0-2-1, such as `#items #helped {
cursor: help }`,
showed its own cursor while ⌥ took the press. The aim's press takes the
item whatever the
  page says about its cursor, so the hand says so.

## Cursors

`test_an_armed_page_shows_each_place_the_cursor_its_press_keeps`
(threads/test_targets.py) reads the cursor where the pointer rests, in
Chromium and in
Firefox. Each place matches main except the four above:

| Pointer over | At rest | ⌥ held | Design mode |
|---|---|---|---|
| words in an item | auto | pointer | pointer |
| beside the column, in no item | auto | auto | auto |
| words in a marked item | pointer | pointer | pointer |
| a tab stop inside a marked item | **auto** (main: pointer) | auto |
auto |
| a marked passage in an item | pointer | pointer | pointer |
| a link in an item | pointer | pointer | pointer |
| an item the page gives `cursor: help` (`#items #helped`) | help |
**pointer** (main: help) | **pointer** (main: help) |
| an item a draft stands on | auto | pointer | |
| a marked ask in a reply, in the panel | auto | **auto** (main:
default) | **auto** (main: default) |

With main's runtime and main's cells in those four places, the test
passes, which
reads main's side of the table. Each of these fails it in both engines:

- `.lf-mark-el`'s pointer rule added back: the tab stop reads `pointer`
in all three
  columns.
- The aim's hand without `!important`: the `help` item reads `help`
under ⌥ and in
  Design mode.
- A hand that reaches chrome marks, `body ~ .lf-chrome .lf-mark-el {
cursor: pointer
  }`: the panel's ask reads `pointer` in all three columns.

Painting the over-mark hand on chrome marks too (`paintHand`) shows no
hand there, and
the test can't see it: the chrome guard (styles/chrome-guard.css) keeps
a rule of one
attribute's weight off chrome elements, behind `markHit`'s own refusal
of the chrome.

## Evidence

Measured at 028adab. The commits after it remove an attribute no
selector read and
make one declaration important.

`uv run leaf-dev bench documents --sizes 64,128,256 --input aim --input
hover --input design --input inspect --input pick --input part --read
cpu --rounds 2 --base`,
Chromium, main-thread CPU in ms per input, the lowest of two rounds,
host load average
11–14:

```
                 8 base   8 head  64 base  64 head 128 base 128 head 256 base 256 head
pick cpu ms        16.7     16.1     23.3     18.6     29.8     22.5     40.6     25.5
part cpu ms        30.3     30.6     34.8     30.9     47.2     35.7     54.5     38.0
aim cpu ms          4.1      3.3      3.8      3.7      5.7      4.5      4.5      4.4
inspect cpu ms      6.1      5.9      6.2      6.3      7.1      7.6      7.3      7.7
design cpu ms      16.2     15.4     19.2     19.5     18.3     20.2     26.1     22.6
hover cpu ms        0.3      0.3      0.2      0.4      0.6      0.7      0.4      0.7
```

`part` no longer grows with the page. `pick` still rises from 16 to 26
ms (exponent
0.56 against main's 0.92), with the hints in view, not the documents:
each Tab repaints
every chip ("Left as it was").

Firefox, on #4781's shape: a script (not committed) that builds the
bench's
`side_documents(224)` with `DOCUMENT_STEPS = 25000`, 1.51 million
elements, serves it
from each arm, and rests the pointer halfway down the open document. It
holds ⌥ down
and lets it up eight times each, 300 ms apart, and enters and leaves
Design mode four
times each, 800 ms apart. Content-process main-thread CPU per gesture,
as the bench
reads Firefox's (`ContentClock`), less the idle rate, load average 5–13:

| | main | this branch |
|---|---|---|
| ⌥ down | 67–73 ms | 11–16 ms, one 52 |
| ⌥ up | 68–73 ms, one 113 | 11–12 ms |
| Design mode in | 77–106 ms | 26–30 ms, the first two 53 and 66 |
| Design mode out | 75–114 ms | 21–26 ms |

On the bench's own `documents` page at 256, about 71,000 elements,
Firefox's `aim` reads
3 to 7 ms on both arms, too small a page to show the walk.

## `namedParts` on an owner with many elements of its own

The walk asks `matches(WORKS)` of each element the owner holds as its
own, which is
slower than one native query over the same elements. In the review's
measurement, a
section holding 50,000 elements of its own, with no addressable inside
it, took 15.8 ms
against 11.4 in Chromium and 37 against 14 in Firefox. The trade still
favours the walk.
The old query read everything under the owner, its members' contents
included, so a
tabs widget holding #4781's 1.5 million rows read all of them on every
press and every
announcement, where the walk reads its own hundred or so. An owner with
tens of
thousands of controls of its own is rare, its cost stays well under the
100 ms a press
has, and those elements are the ones the part's name is counted among.

## Tests

- `test_a_design_part_is_a_repeat_only_among_its_own_owner_s_parts`
(test_render_aim.py): a control inside an item the owner holds leaves
the owner's
same-named control unrepeated, and two of the owner's own are repeats.
It passes on
main's `namedParts`, and fails when the walk doesn't step over
addressables.
- The cursor test above.
- `test_a_mark_in_the_layer_promises_no_press_the_layer_will_not_take`
becomes
`test_a_press_on_a_mark_in_the_layer_opens_no_thread` and keeps its
press. Its cursor
half read each chrome mark's own computed cursor, which no rule sets
now, so it
checked nothing; the cursor test reads that mark where the pointer
rests.
- The 33 waits on `body[data-lf-design-mode]`, in seven test files, wait
for Design
  mode's legend.

Ran `pnpm run test:runtime` (998 passed), `pnpm run check:browser`, and
pre-commit on
the changed files. In each browser test file below, the tests that press
⌥, `s` or `l`,
read a cursor, capture a Design mode target, read the hand's paints or
wait for Design
mode, selected by name: test_render_aim.py (80 passed, 46 subtests, and
the 11 that wait
for Design mode), threads/test_targets.py (6, and 3),
test_chrome_contracts.py (9),
test_render_drawing.py (12), test_render_anchors.py (26),
threads/test_media.py with
`-k "design or part or capture"` (9), navigation/test_key_scopes.py (2),
margin/test_opening_threads.py (2), threads/test_composing.py (4),
controls/test_rings.py (2), margin/test_entries.py (2),
drafts/test_draft_editing.py
(1), test_render_options.py (2), widgets/test_lifecycle_and_controls.py
(1),
widgets/test_contents_and_glosses.py (1), margin/test_status.py (1),
drafts/test_sending.py (1); the journeys that read the page's markup,
arm it or wait
for Design mode, in journeys/test_render_aim.py (7 with parameters),
journeys/test_render_semantic_selection.py (1) and
journeys/test_render_threads.py
(1); and journeys/test_render_gate.py's
`test_the_layer_holds_its_whole_page_rules_on_the_corpus`, which reads
whether the
adopted sheet's order decides anything.

Not run: the whole suite, WebKit, and the daily bench in CI. Not
checked: a desktop
Firefox other than Playwright's, and Max's own #4781 page rather than
its generated
shape.

## Left as it was

- Every picker Tab repaints each hint's chip (`paintTargetPickerHints`,
which reads
`targetBounds` and makes a hit test for each hint), which keeps a picker
Tab at
17–24 ms of main-thread CPU on `documents` whatever hint it lands on,
over the 8 ms a
  keystroke has.

Part of #5194.
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