enhance: eliminate per-block subscription overhead + defer startup work#12464
Open
KonTy wants to merge 2 commits intologseq:masterfrom
Open
enhance: eliminate per-block subscription overhead + defer startup work#12464KonTy wants to merge 2 commits intologseq:masterfrom
KonTy wants to merge 2 commits intologseq:masterfrom
Conversation
added 2 commits
March 21, 2026 22:43
…necessary block fetches Performance fixes: 1. Enable virtual scrolling for mobile journal views (was disabled, causing severe jank on large journals). Use lower threshold (20) on mobile. 2. Defer emoji-mart initialization from module-load to first use. Saves ~200KB of JSON parsing during startup. 3. Skip async db-worker fetch for collapsed blocks on initial render. Only fetch children data when a block is actually expanded. Eliminates hundreds of unnecessary IPC round-trips during page load. Theme improvements: 4. Add live preview on hover in theme picker (t i). Themes now apply instantly as you hover, making it SiYuan-style instant switching. 5. Add live preview on hover for accent color dots (c c). Colors preview on hover and revert on mouse leave.
… debounce Block rendering optimizations: - Hoist state/sub :document/mode? out of block-control — it was already available in config (set once at page level by config-with-document-mode). Eliminates N redundant rum cursor watchers (one per visible block). - Hoist state/sub :rtc/state to page level (config-with-document-mode) instead of subscribing per-block in block-control. Every block was independently watching the full RTC state atom just to check if another user is editing that specific block. - Hoist state/sub :editor/raw-mode-block to page level instead of subscribing per-block in block-content-or-editor. This value is the same for every block — no need for N subscriptions. - Move collapsable? computation from block-control render into block-container-inner-aux (the parent). collapsable? called editor-handler/collapsable? which does entity lookups + property queries. Computing it once in the parent and passing via opts avoids N redundant DB lookups during render. Net effect: eliminates ~4×N state subscriptions and N entity lookups where N = number of visible blocks (typically 50-200). Startup: - Defer instrument/init (PostHog analytics + Sentry error tracking) via requestIdleCallback. These initialize network connections and aren't needed for first render or user interaction. Editor: - Increase block-search ([[) debounce from 50ms to 150ms to reduce excessive DB queries while typing block references.
|
You name seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
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.
🚀 Performance: Eliminating Per-Block Subscription Overhead
The Problem
Every visible block in Logseq independently subscribes to 4 global state atoms that are identical across all blocks. On a page with 200 blocks, that's 800 redundant Rum cursor watchers — all monitoring the same values, all firing their change-detection callbacks on every state mutation, all doing nothing useful.
On top of that, every block's
block-controlcomponent independently callseditor-handler/collapsable?during render, which performs entity lookups and property queries against the DB. That's 200 DB lookups per render cycle that all compute the same kind of data.The Fix
Block rendering (the hot path):
state/sub :document/mode?per blockconfig(already set at page level)state/sub :rtc/stateper blockstate/sub :editor/raw-mode-blockper blockcollapsable?computed per block in renderFor N = 200 visible blocks, this eliminates ~800 state watchers and ~200 entity lookups per render cycle.
The three global subscriptions are hoisted into
config-with-document-mode(called once per page render), and threaded through the existingconfigmap that already flows through the component tree. Zero new architecture — just moving subscriptions to where they belong.Mobile journal virtualization:
Virtual scrolling was explicitly disabled for mobile journal views (
(not (or journal? ...))guard). This caused severe scroll jank on large journals because every block in every journal entry was rendered to DOM simultaneously. Now enabled with a lower threshold (20 blocks on mobile vs 50 on desktop).Deferred initialization:
init()(~200KB JSON parse)instrument/init(PostHog + Sentry)requestIdleCallback(after first paint)Editor:
Block-search (
[[) debounce increased from 50ms → 150ms. The old value caused excessive DB queries while typing — you'd get 4-5 query round-trips for a typical block reference vs 1-2 now.Theme UX:
t i): live preview on hover — themes apply instantly as you browse, revert on mouse leavec c): live preview on hoverFiles Changed
How to Test
t i) and hover over themes — they should preview live[[in a block and start typing — should feel responsive with no lagRisk Assessment
All changes are safe refactors with no behavior changes:
collapsable?is the same function called with the same args, just from one level upinit()function, just called lazily