Skip to content

perf(startup): build the LRU caches empty - #13632

Merged
tiensonqin merged 1 commit into
logseq:masterfrom
yuxi-liu-wired:perf/open-cache
Oct 7, 2026
Merged

tiensonqin merged 1 commit into
logseq:masterfrom
yuxi-liu-wired:perf/open-cache

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

frontend.db.subs creates its warm block cache, and frontend.format.block its block parse cache, with cljs.cache/lru-cache-factory at load, with thresholds of 20000 and 5000. The factory seeds the cache's eviction queue with one placeholder entry per slot, in a priority map, before anything is cached; in CPU profiles of a desktop window reload cljs.cache/build-leastness-queue took about 120 ms (warm cache) and about 90 ms (parse cache) of the renderer's time before the home screen, and the warm cache's again whenever the store is reset for another graph.

Both caches are now built empty, by a new frontend.common.cache/empty-lru (cache/->LRUCache with an empty queue). LRUCache evicts by the queue's real size (miss evicts once it holds limit entries), so an empty cache holds, hits and evicts the same entries.

New test empty-lru-evicts-as-the-factory-cache-test in src/test/frontend/db/subs_test.cljs: the same misses, hits and evictions on an empty-lru and on a factory cache of the same size leave the same entries. frontend.db.subs-test and frontend.format.block-test pass.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 6, 2026
@yuxi-liu-wired yuxi-liu-wired changed the title perf(subs): build the warm block cache empty perf(startup): build the LRU caches empty Oct 6, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 6, 2026
`frontend.db.subs` creates its warm block cache, and `frontend.format.block` its block parse cache, with `cljs.cache/lru-cache-factory` at load, with thresholds of 20000 and 5000. The factory seeds the cache's eviction queue with one placeholder entry per slot, in a priority map, before anything is cached; in CPU profiles of a desktop window reload `cljs.cache/build-leastness-queue` took about 120 ms (warm cache) and about 90 ms (parse cache) of the renderer's time before the home screen, and the warm cache's again whenever the store is reset for another graph.

Both caches are now built empty, by a new `frontend.common.cache/empty-lru` (`cache/->LRUCache` with an empty queue). `LRUCache` evicts by the queue's real size (`miss` evicts once it holds `limit` entries), so an empty cache holds, hits and evicts the same entries.

New test `empty-lru-evicts-as-the-factory-cache-test` in `src/test/frontend/db/subs_test.cljs`: the same misses, hits and evictions on an `empty-lru` and on a factory cache of the same size leave the same entries. `frontend.db.subs-test` and `frontend.format.block-test` pass.
@tiensonqin
tiensonqin merged commit 8cac031 into logseq:master Oct 7, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 8, 2026
devin-ai-integration Bot pushed a commit that referenced this pull request Oct 8, 2026
`frontend.db.subs` creates its warm block cache, and `frontend.format.block` its block parse cache, with `cljs.cache/lru-cache-factory` at load, with thresholds of 20000 and 5000. The factory seeds the cache's eviction queue with one placeholder entry per slot, in a priority map, before anything is cached; in CPU profiles of a desktop window reload `cljs.cache/build-leastness-queue` took about 120 ms (warm cache) and about 90 ms (parse cache) of the renderer's time before the home screen, and the warm cache's again whenever the store is reset for another graph.

Both caches are now built empty, by a new `frontend.common.cache/empty-lru` (`cache/->LRUCache` with an empty queue). `LRUCache` evicts by the queue's real size (`miss` evicts once it holds `limit` entries), so an empty cache holds, hits and evicts the same entries.

New test `empty-lru-evicts-as-the-factory-cache-test` in `src/test/frontend/db/subs_test.cljs`: the same misses, hits and evictions on an `empty-lru` and on a factory cache of the same size leave the same entries. `frontend.db.subs-test` and `frontend.format.block-test` pass.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 11, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 13, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
@yuxi-liu-wired
yuxi-liu-wired deleted the perf/open-cache branch October 21, 2026 18:01
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