Skip to content

Read work in one pass over the scope and its open obligations - #6276

Merged
leaf-agent merged 2 commits into
mainfrom
fix/issue-5722
Nov 17, 2026
Merged

leaf-agent merged 2 commits into
mainfrom
fix/issue-5722

Conversation

@leaf-agent

@leaf-agent leaf-agent commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

readWork grew faster than the page in three ways inside one reading, and this PR removes each. It placed the open widget obligations once per goal. stopped() re-placed a nested goal's obligations once per ancestor. And workEntries ran querySelectorAll("*") over each goal's subtree, with goalView running it again for every descendant to find leaves. Now readWork calls obligationsByRegion once for every goal and computes each goal's stopped once. It also walks the scope a single time, indexing each goal's and worker's children and leaves, and builds each worker's view once. The values a reader gets back are unchanged.

tests/browser/test_render_work.py now also checks each goal's leaves, including a goal held inside another role, and those assertions pass on both the old code and the new. pnpm run test:runtime, pnpm run check:browser and pre-commit pass. No leaf-dev bench collection contains $work widgets. Timed by hand on a tree where every goal holds three subgoals, one reading took 2.8 ms before and 1.2 ms after at 120 goals (four deep), and 33.8 ms before and 13.2 ms after at 1092 goals (six deep). The obligation placement is the fix #6151 made for lf-tabs and lf-deck.

The other half of #6277 is still open. Widgets such as lf-test-task and lf-atlas-worker (examples/command-hub.page) call readWork over the whole scope from each render, so a scope of N tasks still computes the projection N times per paint. Fixing that means sharing one reading per scope and publication. Such a memo would need to keep each reader's selector and clock dependencies (quietSince reads the clock) and to see DOM changes that no selector tracks, so it is left to its own change.

Closes #5722 — automated triage
Part of #6277

readWork called obligationsIn once per goal, and stopped() re-read each child
goal's interventions and stopped state for every ancestor, so a scope's
projection cost goals x open obligations (and more for nested goals). It now
places the open widget obligations for every goal of the scope with one
obligationsByRegion call, keeps the asking widgets' ids in a set, and computes
each goal's stopped once per reading. The projection a reader sees is
unchanged.

Closes #5722
`workEntries` ran `querySelectorAll("*")` over each goal's subtree, and
`goalView` called it again for every descendant to test for leaves, so a
reading cost the page's elements times the square of its nesting depth.
`readWork` now walks the scope once, indexing each goal's and worker's
children and its leaves, and computes each worker's view once rather than
again for the goal it serves. The values a reader gets back are unchanged;
the work test now also pins each goal's leaves, including a goal held inside
another role, and passes on the old code and the new.

On a three-way tree six goals deep (1092 goals) a reading took 33.8 ms
before and 13.2 ms after; at four deep (120 goals), 2.8 ms and 1.2 ms.

Part of #6277
@leaf-agent leaf-agent changed the title Place every goal's interventions in one pass when reading work Read work in one pass over the scope and its open obligations Nov 17, 2026
@leaf-agent
leaf-agent merged commit 4854bad into main Nov 17, 2026
6 checks passed
@leaf-agent
leaf-agent deleted the fix/issue-5722 branch November 17, 2026 08:40
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.

Four runtime paths redo work that grows with the page: lf-suggestion highlights, obligationsIn, lf-toc measuring, Page Map search

1 participant