Repository navigation
perf(db): index history pages and thread metadata reads - #405
Merged
Merged
Conversation
nixuuu
force-pushed
the
perf/db-2-indexes
branch
3 times, most recently
from
November 9, 2026 13:46
25df2f1 to
cab492d
Compare
nixuuu
force-pushed
the
perf/db-2-indexes
branch
from
November 9, 2026 14:02
cab492d to
e4762be
Compare
nixuuu
marked this pull request as ready for review
November 9, 2026 14:04
nixuuu
added a commit
that referenced
this pull request
Nov 9, 2026
Title search ranks narrow headers first, then fetches the existing projected UI metadata for at most 50 matches. Repeated mark-seen requests combine owner validation and monotonic checkpoint persistence in one statement. The history item read applies fork/page predicates before sorting content. This preserves dev c9b57c4's bounded turn-ID window, background-task visibility, metadata projections and activity index. It does not replace the history-window or project-list implementations from #401. Full snapshots and explicit target/from-turn windows retain their existing range; both search reads remain owner/visibility scoped. ## Measurement Before: index layer (#405). After: this read layer. Identical `bun scripts/bench/db.ts --run --explain` runs: PostgreSQL 18.6, 240 threads, 2,048-turn long thread, 4,096-byte texts, two warmups, 20 serial samples. | Operation | Queries before → after | p95 ms before → after | Returned rows before → after | Decoded JSON bytes before → after | |---|---:|---:|---:|---:| | Paged thread open | 10 → 10 | 25.8 → 22.0 | 107 → 107 | 135,392 → 135,392 | | Earlier history page | 10 → 10 | 23.0 → 22.5 | 107 → 107 | 135,392 → 135,392 | | Title search | 1 → 2 | 1,162.7 → 97.3 | 240 → 260 | 844,938 → 98,080 | | Mark seen (repeated checkpoint) | 2 → 1 | 1.6 → 1.6 | 1 → 1 | 49 → 32 | Search returns additional narrow candidate rows while avoiding rich metadata and UI conversion for nonmatches. Candidate title headers still span the owner's active threads to preserve fuzzy ranking. The existing activity index supplies one row per candidate. The paged item query's representative EXPLAIN execution fell from 3.371 to 0.934 ms; top-level shared hits were 377/367 and both returned 84 item rows. Total page row/byte counts are already bounded by #401 and remain unchanged here. EXPLAIN is separate from latency samples. Counts include transaction controls; bytes are decoded JSON, not wire or disk I/O. Shared-host latency varies and is not an SLO. ## Validation and limits Focused migration, history/background/fork/restart/linked passthrough, search ranking/owner/archive/exclusion, read-marker and existing #401 read-cost tests passed on current dev. All required top-branch checks passed: install, gen:check, typecheck, lint, format:check, web build and foreground check:tmp (1,914 pass, 161 skip, 0 fail across 342 files, with nothing left in its temp directory). Details are in #407. Full snapshots, explicit restored windows and persistent background-task rows can still be large. No mirror schema/listing, sync protocol, project reconciliation or new retention changes are included. Polish docs explain the read behavior. No UI text changed; copy audit does not apply. Keep the entire stack as drafts.
This was referenced Nov 13, 2026
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.
Adds 0100_history_read_indexes for unseen turns, selected-turn items, latest side-thread answers and notices. It preserves transcript/durability rows and adds no retention policy.
This builds on dev c9b57c4. Existing migrations 0097–0099 remain unchanged. The activity index already supplied by 0098 is reused, with no duplicate index. Migration registry, expected schema list, index tests and Polish documentation are updated.
Measurement
Before: current-dev benchmark layer (#404). After: this index layer only. Both use
bun scripts/bench/db.ts --run --explain, PostgreSQL 18.6, identical 240-thread/2,048-turn/4,096-byte fixtures, two warmups and 20 serial samples.EXPLAIN captures the new unseen, per-turn item and notice indexes in these reads. The latest-answer index targets the existing side-thread preview query; the default fixture has no side threads, so this table makes no isolated latency claim for that index. All new indexes are checked for validity/idempotent migration. Shared-host latency varies; returned JSON bytes are not wire/disk I/O or scanned-row counts. Counts include transaction controls.
Rollout and validation
CREATE INDEX CONCURRENTLY. These index builds block table writes; large server databases need a maintenance window. Online index migration support remains separate work.No UI text changed; copy audit does not apply. Keep every PR in the stack as a draft.