Repository navigation
enhance(state): only re-evaluate subscriptions that read a changed path - #13213
yuxi-liu-wired wants to merge 4 commits into
Conversation
|
@yuxi-liu-wired Please sign the CLA so that we can review and merge those PRs, thanks! |
9b4b9ee to
084555e
Compare
|
Merged latest master (no conflicts) and simplified:
|
42f0707 to
084555e
Compare
…store Every keystroke wrote four values through state/set-state!: the block text, the last input time, the last key code, and the saved cursor position. Each write makes the state store re-evaluate every mounted subscription, so on a page with many blocks a keystroke ran that sweep four times. The last input time, the last key code, the saved cursor, and the UI's last key code are read imperatively by the editor handlers through their getters; no component subscribes to them. Keep them in plain atoms, remove their keys from the store's initial state and from the places that reset them, and drop the store save/restore of the saved cursor from state_test. A keystroke now writes the store once, for the text. Measured on a 2,000-page graph, typing into a block on a 204 KB page (key press to next frame, p50 / p90 / max, 83 keys): before 44.7 / 50.7 / 66.3 ms, after this change 34.9 / 49.5 / 88.3 ms.
:editor/last-key-code was only ever written, never read (the store key had no getter; the keyup handler stored a map that nothing consumed). Keeping it as a private atom preserves dead bookkeeping, so remove the atom, the setter, and its call sites entirely.
state/set-state! and state/update-state! know which app-db path they change, and frontend.state registers every state key k as a subscription [k & path] reading (get-in (get db k) path). Tell the rfx store both facts: bind store/*changed-paths* around next-state! and install a sub-key fn that maps [k & path] to [k (first path)] and [::state-key k] to [k nil]. The store then evicts and recomputes only the subscriptions reading those paths on each write instead of every mounted subscription. Writes without a path (swap-state!, event :db effects) are handled by the store's two-level comparison of the previous and next db. Depends on the rfx change "Recompute only the subscriptions that read a changed app-db path"; deps.edn points at that commit on the fork and will be repointed to upstream rfx once that change merges. Measured on a 2,000-page graph, on a 204 KB page: moving the editing cursor between blocks with ArrowDown/ArrowUp (key press to next frame, p50 / p90 / max) 44.4 / 50.2 / 76.5 ms before, 20.8 / 31.2 / 47 ms after the full set of changes; a click into a block paints after 48 ms instead of 160 ms; long tasks over 50 ms during 40 block moves: 38 before, 0 after.
set-state! took a :changed-paths option that no caller passes; replace-state! already reports the written path to the store.
084555e to
0145d74
Compare
|
Rebased onto current master, on top of #13210 including its |
There was a problem hiding this comment.
🔍 Devin Review: 2 flags
Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)
|
The red "Test outliner-rtc" on this PR (run 36056373275) is the Rerun locally, the web build with the CI e2e defines, this branch beside its upstream base
What makes it flaky, from a probe that repeats the test's steps 180 times per build: after the delete, b3's editor appears 38 to 140 ms later, and the test presses Shift+ArrowUp without waiting for it. When the editor arrives after the first press, that press is lost, which gives the line 139/140 shape (3 iterations on this branch, 6 on upstream). The second shape is |
What changes
A write to the app state store re-evaluates only the subscriptions that read the changed path instead of every mounted subscription.
Mechanism
Depends on the rfx change "Recompute only the subscriptions that read a changed app-db path".
deps.ednpoints at that commit on the fork; it will be repointed to upstream rfx once that change merges.state/set-state!andstate/update-state!know which app-db path they change, andfrontend.stateregisters every state keykas a subscription[k & path]with the single signal[::state-key k]whose function is(get-in value path).frontend.rfxnow tells the store both facts:replace-state-paths!bindsstore/*changed-paths*aroundnext-state!, andsub-keymaps[k & path]to[k (first path)]and[::state-key k]to[k nil](any other subscription is left to its declared signals). Writes without a path (swap-state!, rfx event:dbeffects) fall back to the store's two level comparison of the previous and next db.Concretely, typing rewrites
[:editor/content uuid]and only the popups subscribed to that path are re-evaluated; moving the editing cursor rewrites:editor/editing?and only the 2 blocks whose[:editor/editing? [container-id uuid]]entry changed are re-evaluated, not every mounted block.Numbers
On a 204 KB page of a 2,000 page graph, Chromium 148 renderer driven over the DevTools protocol,
requestAnimationFrameafter each key, p50 / p90 / max: moving the editing cursor between blocks with ArrowDown / ArrowUp, 44.4 / 50.2 / 76.5 ms before the full set of changes and 20.8 / 31.2 / 47 ms after; a click into a block painted after 160 ms (max 240) before and 48 ms (max 64) after; tasks over 50 ms during 40 block moves: 38 before, 0 after. In a CPU profile of typing before this change, the store sweep triggered by the window keydown handler cost about 15 ms per key and the:editor/contentwrite about 12 ms per key; after it,next-state!no longer appears above 1 % of the profile.Tests
The existing unit suite on the 4 branches combined, compiled with
pnpm cljs:testand run with the grouping ofbb dev:run-test-namespaces(213 namespaces, 2106 tests, 8650 assertions): every test passes exceptfrontend.handler.db-based.import-test/import-from-sqlite-db-persists-import-marker-through-worker-test, whose 5 assertions fail identically on unpatched master (be800f1) whenever that namespace shares a node process with the 6 namespaces the runner groups it with, and pass when the namespace runs alone. One wall-clock assertion infrontend.worker.search-test(sync-search-indiceof 300 blocks under 1000 ms with semantic search disabled) measured 1194 ms in one run and passed on reruns; the worker code is untouched by these branches. With one node process per namespace the suite is fully green. The store behaviour itself is tested in the rfx change.Allow edits from maintainers.