Repository navigation
perf(block): draw no row below the fold before a page's first paint - #13546
yuxi-liu-wired wants to merge 3 commits into
Conversation
| (hooks/use-layout-effect! | ||
| (fn [] | ||
| (when (and first-paint rows?) | ||
| (if virtualized? | ||
| (close-first-paint-session! first-paint) | ||
| (schedule-first-paint! first-paint)))) | ||
| [rows? virtualized?]) |
There was a problem hiding this comment.
🟡 Empty pages retain global input listeners
On an empty page, rows? stays false, so schedule-first-paint! never closes the session. Three capture listeners remain active until input or navigation.
Learn more
A standalone page always renders the root list even when it has no blocks. The first-paint session installs window input listeners in listen-first-paint-input!, but this effect runs only when rows? is true. On an empty page, no animation frame or timeout closes the session. The listeners remain until navigation unmounts the page or a captured input closes the session.
Example: Open a new empty page and leave it idle. Its keydown, pointerdown, and wheel capture listeners remain installed indefinitely instead of being removed after the first frame.
Recommended fix: Distinguish pending row loading from a resolved empty list, and close the session when the empty result is known. Preserve the delayed scheduling for pages whose block UUIDs are still loading.
Was this helpful? React with 👍 or 👎 to provide feedback.
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
logseq#13545, logseq#13546 and logseq#13547 replace the 9 open pull requests they bundle; logseq#13468, logseq#13437, logseq#13475 and logseq#13528 are in upstream master.
9fccf29 to
a71a4e9
Compare
aedf3b5 to
acdf3a8
Compare
Opening a page mounted, before its first paint, every children subtree that started within 1200 px below the viewport. lazy-block-children decides this in a layout effect through getBoundingClientRect, so each nesting level also forced a layout. On a 700 px window, quantization (92 blocks) shows 13 rows on screen but mounted 54 rows, the lowest at 3169 px, before its first frame. In 1 ms CPU profiles of a cold open that render task took 326-362 ms: component code 155 ms, forced layout 71 ms in 4 reads (one per nesting level), mldoc parse 49 ms. The IntersectionObserver fallback, meant to mount the rest with the same 1200 px margin, used the window as its root. #main-content-container still clips rows below its fold, so the margin never applied: after a 700 px scroll, placeholders 551-1023 px below the viewport stayed unmounted for 1.5 s, until scrolled into view. The layout-effect check now mounts only subtrees that reach into the viewport (the margin above it stays), and the observer's root is the scroll container, so its margin applies: subtrees below the fold mount in the frames right after the first paint. Measured over 3 interleaved relaunched runs per build, medians (ranges) of the frame at which every row on screen is in the DOM: - quantization: cold 935 (866-1051) -> 711 (690-752) ms, warm 227 (152-248) -> 92 (68-95) ms, warm2 204 (147-235) -> 112 (107-135) ms - computer vision (389 blocks): cold 887 (569-896) -> 681 (668-774) ms, warm 219 (213-309) -> 131 (110-147) ms, warm2 212 (193-258) -> 128 (80-148) ms - 3 small pages (9-21 blocks), Tracy-Widom distribution (65) and Douglas Lenat (742): within run-to-run spread, except Tracy-Widom warm2 221 (209-233) -> 179 (114-182) ms. Their rows below the fold are top-level rows, which still mount eagerly. The last rows below the fold arrive later: on the 3 pages with deferred rows, the frame at which all initially mounted rows are present moves later in 8 of 9 medians, by 16 to 145 ms.
Opening a page rendered, before its first paint, every row of a list under 64 rows: the page's top-level rows, and every row of a children list whose top was on screen. On a 700 px window, Theory of small talk (13 top-level rows) built 13 rows to show 6, J G Ballard 21 to show 11, Scholasticism 36 to show 16 (19 of its 20 rows below the fold sit in a children list that starts on screen), quantization 54 to show 13. A list of the page outliner that mounts during the page's first paint now renders its first row only. In the task that brings the rows, and again in the frame before the paint, the lists whose rendered rows end above the bottom of the viewport grow, innermost first, until the rows on screen are all there; the rest of each list mounts in the task after the paint. Rows stay direct children of their .blocks-list-wrap, as the editor's sibling walks expect, and render as a prefix of the list with the same keys. A key, pointer or wheel event before the rest mounts renders it first, inside flushSync, from a capture listener on window. Anchor routes, restored scroll offsets, embeds, journals, the sidebar and virtualized lists render as before. Measured on 5 pages, 3 pinned interleaved relaunched runs per build. Rows built before the rows on screen are complete, the same in every run, cold and warm; rows on screen and at settle are unchanged: - Theory of small talk 13 -> 6, J G Ballard 21 -> 12, Scholasticism 36 -> 16, quantization 54 -> 13; countercurrent flow (all rows on screen) 9 -> 9 - on top of the children deferral of perf/row-rendering: 13 -> 6, 19-20 -> 12, 36 -> 16, 16-20 -> 13 Frame at which the rows on screen are complete, medians (ranges): - Theory of small talk: cold 373 (360-1154) -> 333 (225-341) ms, warm 85 (69-86) -> 71 (67-71) ms, warm2 81 (79-83) -> 66 (63-67) ms - J G Ballard: cold 418 (416-418) -> 380 (376-416) ms, warm 119 (79-120) -> 96 (95-103) ms, warm2 72 (72-108) -> 61 (56-89) ms - Scholasticism: cold 693 (686-698) -> 561 (402-633) ms, warm 143 (97-143) -> 96 (68-101) ms, warm2 91 (88-144) -> 88 (59-94) ms - quantization: cold 993 (676-1011) -> 730 (728-744) ms, warm 263 (199-276) -> 90 (72-92) ms, warm2 265 (172-278) -> 86 (57-87) ms - countercurrent flow: cold 371 -> 370 ms, warm 72 -> 80 ms, warm2 68 -> 74 ms, overlapping ranges The DOM at settle, arrow keys and Shift+ArrowDown across the first deferred row, scroll to an anchored row, drag and drop of a deferred row, and Enter at the last row on screen gave the same result as before in the app.
The session was scheduled only once the page had rows, so on an empty page its window capture listeners for keydown, pointerdown and wheel stayed until input or navigation. The list now tells loading rows (nil, as use-children reads) from a loaded empty page and schedules the session for both; the Library list keeps nil while its blocks load instead of an empty list.
acdf3a8 to
8f3ee9e
Compare
|
Combined into #13872 with the other PRs of this theme, to keep the number of open PRs down; the commits are unchanged there. |
This brings #13447 and #13451 into 1 pull request, so they merge once. Both change what an opened page draws before its first paint, and both edit the same block component (
src/main/frontend/components/block.cljs). The branch is on current master. Each part keeps its own commit, unchanged, so the review can go commit by commit. The old pull requests are closed with a link here; their review threads stay there.Commits, in order:
perf(block): mount below-fold children after paint(perf(block): mount below-fold children after paint #13447)perf(block): defer rows below the fold on open(perf(block): defer rows below the fold on open #13451)Tests
The whole unit suite on this branch (master
68a68263bplus these commits), with thedb-worker-nodetarget compiled: atTZ=Etc/GMT+122575 tests, 12850 assertions; atTZ=Pacific/Kiritimati, the date-dependent namespaces, 1520 tests, 9319 assertions: 0 failures, 0 errors.The descriptions of the parts follow, as each pull request had them.
#13447: perf(block): mount below-fold children after paint
What changes
Opening a page mounted, before its first paint, every children subtree whose top lay within 1200 px below the viewport. On a 700 px window,
quantization(92 blocks) shows 13 rows but mounted 54 rows, about 4 screens, before its first frame, in 1 task of 250-356 ms cold and 114-174 ms warm.lazy-block-childrendecides this in a layout effect throughgetBoundingClientRect, so each nesting level also forced a layout: in 1 ms CPU profiles of a cold open, that task spent 71 ms in 4 forced layouts, 155 ms in component code and 49 ms in the mldoc parse.The layout-effect check (
near-block-viewport?) now mounts only subtrees that reach into the viewport; the 1200 px margin above it stays, so content above a scrolled position still mounts before paint and nothing on screen shifts. The IntersectionObserver fallback now takes the page's scroll container as its root (lazy-children-observer-root), so subtrees below the fold mount in the frames right after the first paint.This also fixes the observer's margin. With the window as root,
#main-content-containerclipped the rows below its fold, so the 1200 px margin never applied: after a 700 px scroll, placeholders 551-1023 px below the viewport stayed unmounted for 1.5 s, until scrolled into view. With the scroll container as root, a scroll of 700, 1500 or 2500 px leaves no placeholder within 1200 px of the viewport's bottom edge on the 2 pages checked (quantizationkept 3, 1 and 4 before;computer vision0, 5 and 2).Numbers
Desktop release builds of master (
d9d625847) and of this branch, each shipped as only the renderer bundle in the same nightly app shell, on an imported graph of about 154k blocks. 3 runs per build, alternating build by build, each run relaunching the app per page, then opening it cold and twice warm. Medians (ranges) in ms of the frame at which every row on screen is in the DOM:The 3 small pages (9-21 blocks),
Tracy-Widom distribution(65 blocks) andDouglas Lenat(742 blocks) do not change beyond run-to-run spread: their rows below the fold are top-level rows, which this change leaves eager (top-level rows render eagerly below 64,use-virtual-list-opts).Combined with #13437 (request order), 6 runs per build:
quantizationshows its rows on screen at 312 instead of 406 ms cold (ranges overlap) and at 86-93 instead of 214-234 ms warm.The price is below the fold: on the 3 pages with deferred rows, the frame at which all rows mounted by the old code are present comes later in 8 of 9 medians, by 16 to 145 ms (up to 219 ms combined with #13437). Those rows are 1-4 screens down.
Tests
frontend.components.block.lazy-children-test(new): the layout-effect check mounts subtrees that reach into the viewport, leaves subtrees below the fold to the observer even within the margin, and keeps the margin above; the observer's root is the scroll container only when it holds the subtree. The below-the-fold assertions fail on master.TZ=Etc/GMT+12(2478 tests, 12418 assertions) and the time-zone-dependent namespaces atTZ=Pacific/Kiritimati(1446 tests, 8979 assertions): the only failures are the zone-dependent tests that fix(test): build test dates in local time #13430 fixes (6 and 4 assertions), the same as on master.#13451: perf(block): defer rows below the fold on open
What changes
Opening a page rendered, before its first paint, every row of a list under 64 rows: the page's top-level rows, and every row of a children list whose top was on screen. On a 700 px window,
Theory of small talk(13 top-level rows) built 13 rows to show 6,J G Ballard21 to show 11,Scholasticism36 to show 16 (19 of its 20 rows below the fold sit in a children list that starts on screen), andquantization54 to show 13.Now a list of the page outliner that mounts during the page's first paint renders its first row only. In the task that brings the rows, and again in the frame before the paint, the lists whose rendered rows end above the bottom of the viewport grow, innermost first, until the rows on screen are all there. The rest of each list mounts in the task after the paint.
.blocks-list-wrap, as the editor's sibling walks (get-node-prev-sibling,get-node-next-sibling) expect, and render as a prefix of the list with the same keys.flushSync, from a capture listener onwindow, so input never acts on a partial list. The session, and so its listeners, ends after the first frame once the page's rows are known, an empty page's included; while they load (use-childrenreads nil) it waits. The Library list keeps nil while its blocks load, instead of an empty list.This complements #13447, which defers nested children lists that start below the fold. The 2 branches merge without conflict.
Numbers
Desktop release builds of master (
d9d625847) and of this branch, shipped as the renderer bundle in the same nightly app shell, on an imported graph of about 154k blocks. 3 interleaved relaunched runs per build, each opening the page cold and twice warm.Rows built before the rows on screen are complete. This count was the same in every run, cold and warm. The rows on screen and the rows at settle don't change:
Frame at which every row on screen is in the DOM, medians (ranges) in ms:
Tests
frontend.components.block.first-paint-rows-test(new, 8 tests): when the session waits (rows loading), is scheduled (rows known, none included) or closes at once (a virtualized list); that the Library list reads nil while it loads; which opens defer (a page opened from its route) and which render every row (an open that must reach a row below the fold, anything but the standalone page outliner); how many rows fill the viewport; which list grows first (the innermost that ends above the fold, then its parent); that closing the first-paint session mounts every deferred tail; and filling the viewport on flat and nested lists.TZ=Etc/GMT+12(2482 tests, 12439 assertions) and the time-zone-dependent namespaces atTZ=Pacific/Kiritimati(1446 tests, 8979 assertions). The only failures are the zone-dependent tests that fix(test): build test dates in local time #13430 fixes, and the elapsed-time bounds infrontend.worker.graph-view-testandfrontend.worker.search-test(Unit tests: assert on work done instead of elapsed time #13446), which pass when run alone on a quiet machine.Allow edits from maintainers.