Skip to content

perf(block): defer rows below the fold on open - #13451

Closed
yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:perf/top-level-rows
Closed

yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:perf/top-level-rows

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

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 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), and quantization 54 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.

  • Rows stay direct children of their .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.
  • A key, pointer or wheel event that arrives before the rest mounts first renders it, inside flushSync, from a capture listener on window, so input never acts on a partial list.
  • Anchor routes, restored scroll offsets, embeds, journals, the sidebar and virtualized lists render as before.

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:

page master this branch this branch with #13447
Theory of small talk 13 6 6
J G Ballard 21 12 12
Scholasticism 36 16 16
quantization 54 13 13 (16-20 with #13447 alone)
countercurrent flow (all 9 rows on screen) 9 9 9

Frame at which every row on screen is in the DOM, medians (ranges) in ms:

page cold warm warm again
Theory of small talk 373 (360-1154) -> 333 (225-341) 85 (69-86) -> 71 (67-71) 81 (79-83) -> 66 (63-67)
J G Ballard 418 (416-418) -> 380 (376-416) 119 (79-120) -> 96 (95-103) 72 (72-108) -> 61 (56-89)
Scholasticism 693 (686-698) -> 561 (402-633) 143 (97-143) -> 96 (68-101) 91 (88-144) -> 88 (59-94)
quantization 993 (676-1011) -> 730 (728-744) 263 (199-276) -> 90 (72-92) 265 (172-278) -> 86 (57-87)
countercurrent flow 371 -> 370 72 -> 80 68 -> 74 (ranges overlap)

Tests

  • frontend.components.block.first-paint-rows-test (new, 7 tests): 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.
  • In the app, on both builds: the DOM at settle; ArrowUp/ArrowDown 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. All gave the same result.
  • The whole unit suite at TZ=Etc/GMT+12 (2482 tests, 12439 assertions) and the time-zone-dependent namespaces at TZ=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 in frontend.worker.graph-view-test and frontend.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.


Devin Review

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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

Comment on lines +5210 to +5212
(loop [pass 0]
(when (and (first-paint-session-open? session)
(< pass first-paint-max-passes))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Deep outlines paint with missing rows

When over 64 nested lists fit onscreen, fill-viewport! stops before reaching their deepest rows. Each pass reveals only one nested list, leaving visible rows absent until the post-paint task.

Learn more

The page outliner renders one row per flat list initially. A child list mounts only after its parent renders the row holding it, so a nested chain can advance by only one level per growth pass. schedule-first-paint! calls fill-viewport! twice, once in a microtask and once in an animation frame, making the 32-pass cap an effective 64-level limit before paint. The remaining rows mount when close-first-paint-session! runs in the later timer.

Example: In a 2400-pixel viewport, 70 expanded nested blocks of approximately 28 pixels each can fit below a page title. The 65th child's list is not reached by either pre-paint pass, although it is onscreen; it appears with the deferred tail afterward.

Recommended fix: Continue growth while an open-ended visible nested list remains, or detect exhaustion of first-paint-max-passes and synchronously mount the remaining tails before paint. Add a nested-chain test that crosses the combined pass budget.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Continued in #13546 together with #13447: they share files, so they now merge once. The commits are the same, on current master.

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.

1 participant