Skip to content

perf(page): tag page body waits for table paint - #13435

Merged
tiensonqin merged 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/tag-page-first-paint
Sep 26, 2026
Merged

tiensonqin merged 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/tag-page-first-paint

Conversation

@yuxi-liu-wired

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

Copy link
Copy Markdown
Contributor

What changes

A tag page no longer holds back its body (bidirectional properties, block tree, class children, linked references) for a fixed 800 ms. The body now mounts once the objects table has its first window. The 800 ms stays only as a cap for a table that never reports. On an imported graph of about 150k blocks, a warm tag page showed its first screen of blocks after 201-529 ms instead of 888-1007 ms (medians per page), and a cold one after 837-979 ms instead of 1008-1299 ms.

Mechanism

#13226 wrapped the body of a class page in after-first-paint, which renders nothing until a setTimeout of 800 ms fires. The purpose was to let the objects table's first :view-data request leave in its own snapshot batch, before the children tree and the linked references ask for theirs. The timer runs the same 800 ms whether the table answered after 10 ms or not at all, so on a warm open the page below the table stayed empty for about 700 ms with the renderer idle.

class-objects already hands :on-first-table-paint! to the view. view-inner calls it from its mount effect, and sub-view mounts view-inner only after the first-window :view-data response has arrived. page-inner now passes a release callback through tabs to class-objects, which calls it next to its own set-first-paint-done!. The new hook use-below-fold-ready returns [ready? release!]. ready? is true at once on pages that are not tags. On tag pages it becomes true on release! or when the 800 ms cap fires. release! is memoized with use-callback, because hsx/defc compares component arguments with =, and a new function on every render would re-render tabs and the table at the moment the body is released.

The release follows the first-window response, so the body's snapshot requests always leave after that request. They now queue in subs-loader behind the table's second :view-data request, which asks for the remaining rows and flushes first as a view resource. In request logs of 12 tag-page opens (4 tags, cold and warm) on master and on this branch, the first-window request carried only that resource and was sent before any body request every time.

The 800 ms delay of the reference count in loaded-page is unchanged. The body's references component asks for the same resource when it mounts.

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 the same imported graph (2086 pages, about 147k blocks). Each run relaunches the app per page, then opens the page cold and twice warm. The builds alternate run by run, with 3 runs per build (4 for ergodic theory). Medians in ms from navigation to the frame after the DOM change:

page phase first screen of blocks, master this branch table's first rows, master this branch
tag with 1 object and 424 blocks cold 1299 837 188 158
same warm 943 357 96 97
tag with 2 objects and 1265 blocks cold 1179 979 173 168
same warm 963 201 126 84
tag with 92 objects cold 1008 924 498 468
same warm 899 463 110 275
built-in Page tag, 2686 objects, body is the add-button row cold 961 374 366 374
same warm 832 259 215 259
page that is not a tag, 733 blocks cold 690 769 - -
same warm 189 158 - -

On a cold open the body still waits for the table's remaining-rows request (152-518 ms in these runs), which walks the sort index when there is no row limit. A separate pull request, "perf(views): sort small sets without a row limit", addresses that for tags with up to 1000 objects. On the 92-object tag warm, the median time to the table's first rows was later on this branch (275 ms against 110 ms, ranges 124-314 and 90-143 ms over 3 runs). The body now mounts in the same frames as the table, so its first render can run before the table's rows paint.

Tests

  • frontend.components.page-first-paint-test: the new class-page-body-waits-for-the-first-table-window-test runs the hook with stubbed use-state, use-callback and use-effect!. A page that is not a tag is ready without a timer. A tag page waits and arms the 800 ms cap. The release callback is memoized with empty deps and sets the state to true. Once released, the cap is cleared. The old assertion that the delay is at least 400 ms is kept as a check on the cap.
  • frontend.components.page-first-paint-test, frontend.components.page-test, frontend.db.subs-loader-test, frontend.db.subs-test, frontend.components.views-test, frontend.components.journal-test: 0 failures, run with TZ=Etc/GMT+12 and TZ=Pacific/Kiritimati.
  • The whole unit suite, once with TZ=Etc/GMT+12 and once with TZ=Pacific/Kiritimati: 2477 tests, 12415 assertions each. The only failures are the 3 zone-dependent tests that fix(test): build test dates in local time #13430 fixes (6 assertions at UTC-12, 4 at UTC+14), the same as on master.
  • clj-kondo on the 3 changed files: 0 errors, 0 warnings.

Allow edits from maintainers.


Devin Review

@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: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

A tag page held its bidirectional properties, block tree and linked
references behind a fixed 800 ms timer, so that the objects table's
first view-data request leaves in its own batch. The timer ran on every
tag page, whether the table had answered after 10 ms or not at all.

Release the body when the objects table reports its first window,
through the on-first-table-paint! callback class-objects already passes
to the view. The view reports only after that window's view-data
request has answered, so the body's snapshot requests always leave
after it. The 800 ms stays as a cap for a table that never reports.
The release callback keeps its identity across renders: a new function
per render would defeat the memo of the tabs and re-render the table
when the body is released.
@tiensonqin
tiensonqin force-pushed the fix/tag-page-first-paint branch from c06957a to 627f045 Compare September 26, 2026 12:57
@tiensonqin
tiensonqin merged commit 71cd93a into logseq:master Sep 26, 2026
16 checks passed
@yuxi-liu-wired
yuxi-liu-wired deleted the fix/tag-page-first-paint branch September 30, 2026 20:02
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.

2 participants