Repository navigation
Read work in one pass over the scope and its open obligations - #6276
Merged
Merged
Conversation
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
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.
readWorkgrew 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. AndworkEntriesranquerySelectorAll("*")over each goal's subtree, withgoalViewrunning it again for every descendant to find leaves. NowreadWorkcallsobligationsByRegiononce for every goal and computes each goal'sstoppedonce. 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.pynow 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:browserand pre-commit pass. Noleaf-dev benchcollection contains$workwidgets. 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 forlf-tabsandlf-deck.The other half of #6277 is still open. Widgets such as
lf-test-taskandlf-atlas-worker(examples/command-hub.page) callreadWorkover the whole scope from eachrender, 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 (quietSincereads 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