Repository navigation
build(bench): measure gateway database workloads - #404
Merged
Merged
Conversation
nixuuu
force-pushed
the
perf/db-1-bench
branch
from
November 9, 2026 13:37
756bc55 to
185e0f1
Compare
nixuuu
force-pushed
the
perf/db-1-bench
branch
from
November 9, 2026 13:46
185e0f1 to
58c563e
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
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 **c9b57c42**. 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 #407. No UI text changed; copy audit does not apply. Keep every PR in the stack as a draft.
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 an opt-in synthetic PostgreSQL 18 benchmark for gateway stores, an SQL inventory, sanitized EXPLAIN diagnostics and Polish usage documentation. It reuses production Effect SQL services without enabling tracing in the application.
The harness owns its Docker container and private data directory, caps resources, never accepts an existing database URL and removes its dataset afterwards. Latency uses the normal pool; a separate pass counts statements, returned rows and decoded JSON bytes without emitting SQL values.
Baseline and measurement
The baseline was remeasured on dev c9b57c4, including #400–#402. This layer adds measurement only. Earlier measurements against pre-incident dev are superseded and are not used for this stack's comparisons.
Command:
bun scripts/bench/db.ts --run --explain. PostgreSQL 18.6, 240 threads, 24 projects, 13 workers, 32 turns per ordinary thread, 2,048 in the long thread, 4,096-byte texts, 64 background tasks, attachment metadata, bots/history, schedules and one linked mirror. Two warmups, 20 serial samples, nearest-rank p95; approximately 140 MB of storage.The compact mirror list, bounded turn window, projected UI metadata, indexed activity and scratch workspace reconciliation already belong to current dev. This stack does not claim those improvements.
Counts include transaction controls. Rows/bytes are returned to JavaScript, not all scanned rows, wire bytes or physical I/O. Empty result arrays contribute two JSON bytes each. EXPLAIN nodes expose rows/loops and shared/temp buffers; pg_stat_statements supplies server counters. Shared-host load varies; these timings are observations, not SLOs.
Coverage and validation
Seventeen operations cover project/thread lists, full and paged opens, queue/steer, mark seen, title search, tasks, bot history, updates, mirrors and import admission/read. These are store operations, not full RPC benchmarks. Update fixtures currently return no update rows, and the mirror fixture has one mirror. The inventory finds 2,095 statement/fragment locations including migrations; this is not a completed manual audit of every SQL statement.
Default baseline, intermediate layers and top benchmarks completed with EXPLAIN; owned containers/datasets are removed. Benchmark output and logs are not committed. All required top-branch checks passed: bun install, gen:check, typecheck, lint, format:check, foreground check:tmp and the web build. The full run passed 1,914 tests, skipped 161 opt-in/platform tests and failed none across 342 files; check:tmp reported nothing left in its temp directory. Focused current-dev checks also passed. Full validation details are in #407.
Next coverage should add concurrent mixed load, populated update fixtures, many large mirrors, side-thread previews and attachment/import payload scaling. No UI text changed; copy audit does not apply. Keep the entire stack as drafts.