Skip to content

perf(db): index history pages and thread metadata reads - #405

Merged
nixuuu merged 1 commit into
perf/db-1-benchfrom
perf/db-2-indexes
Nov 9, 2026
Merged

nixuuu merged 1 commit into
perf/db-1-benchfrom
perf/db-2-indexes

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

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.

Operation Queries before → after p95 ms before → after Returned rows before → after Decoded JSON bytes before → after
Sidebar threads 1 → 1 12.8 → 9.7 240 → 240 847,006 → 847,006
Full thread open 7 → 7 56.4 → 55.0 4,162 → 4,162 11,544,594 → 11,544,594
Paged thread open 10 → 10 29.8 → 25.8 107 → 107 135,392 → 135,392
Earlier history page 10 → 10 26.9 → 23.0 107 → 107 135,392 → 135,392

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

  • Migration/schema/populated-upgrade checks passed (26 tests). The existing 0098 migration flushes deferred constraint events before index DDL in a multi-migration upgrade; this layer does not change that policy.
  • The transactional migrator cannot use CREATE INDEX CONCURRENTLY. These index builds block table writes; large server databases need a maintenance window. Online index migration support remains separate work.
  • Indexes add storage and write cost. Number 0100 is highest dev migration + 1; renumber if another migration lands before this one.
  • Current-dev focused integration checks and every required top-branch check passed. Foreground check:tmp: 1,914 pass, 161 skip, 0 fail across 342 files, with nothing left in its temp directory. Install, gen:check, typecheck, lint, format:check and web build also passed; details are in perf(db): batch import admission writes #407.

No UI text changed; copy audit does not apply. Keep every PR in the stack as a draft.

@nixuuu
nixuuu added this pull request to stack #408 November 9, 2026 13:05
@nixuuu
nixuuu force-pushed the perf/db-2-indexes branch 3 times, most recently from 25df2f1 to cab492d Compare November 9, 2026 13:46
@nixuuu
nixuuu force-pushed the perf/db-2-indexes branch from cab492d to e4762be Compare November 9, 2026 14:02
@nixuuu
nixuuu marked this pull request as ready for review November 9, 2026 14:04
@nixuuu
nixuuu merged commit a37183f into dev Nov 9, 2026
11 checks passed
@nixuuu
nixuuu deleted the perf/db-2-indexes branch November 9, 2026 14:16
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.
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.

1 participant