perf: optimize everyday query hot paths#74
Merged
Conversation
ferueda
marked this pull request as ready for review
July 23, 2026 19:06
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.
Summary
limit + 1compact coordinates through an explicit indexed source → tracking → canonical → entry traversal, then hydrate only the pageWhy
A real 4,544-session / 3.57-million-entry library exposed a broad 50-entry query taking roughly 4.5–6 seconds warm. SQLite entered through
sessions_entries, scanned broadly, and built a temporary ordering B-tree before applying the page limit. Search hydration also repeated selected-content, context, and summary reads per hit, while CLI startup eagerly loaded handlers that version/help did not need.Performance evidence
Entries
The shipped statement now enters through source/tracking/canonical rows, uses existing indexes, avoids the entry-first full scan and full temporary sort, and stops at
limit + 1. On the generated skew corpus (2,001 sessions, 212,000 entries):The deep plan uses keyset continuation and contains no
OFFSETor temporary ordering sort. The original 4.5–6 second number came from the larger live library, so it is root-cause evidence rather than a same-corpus percentage claim; the repeatable generated measure is the regression baseline going forward.Search
Before, selected content, context, and summary hydration grew through repeated point reads. After, selected content and linked discovery are page-wide, summaries are batched, and distinct context bodies hydrate in fixed 200-coordinate chunks. In the maximum-page generated profiles, selected-content work remained one statement and SELECT authorization counts stayed constant at 28 for
all/ 31 foranywithout context; the measured context profile added four authorizations. Wall time remained roughly 15–31 ms depending on page size, term mode, and context.A one-pass
MATERIALIZEDsearch prototype preserved semantics and reduced the qualifying FTS scan to one, but was about 15% slower over broad profiles rather than meeting the 20% improvement gate. It was removed from runtime code.CLI startup
Compiled warm medians, before → after:
--versionlistPlanner statistics were also tested on byte-identical clones. Entry plans did not improve and several list/search profiles regressed, so no runtime
ANALYZEorPRAGMA optimizepolicy was added.Compatibility and correctness
first/last, corruption failures, stale/mismatched cursor behavior, and snapshot semantics remain exactVerification
pnpm check20260723-185502-c6e50f: implementation pass, code quality pass, zero findings