Repository navigation
perf(block): mount below-fold children after paint - #13447
Closed
yuxi-liu-wired wants to merge 1 commit into
Closed
yuxi-liu-wired wants to merge 1 commit into
yuxi-liu-wired wants to merge 1 commit into
Conversation
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.
This was referenced Sep 26, 2026
Contributor
Author
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.
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.Allow edits from maintainers.