Reduce event-history query work and bound cleanup batches - #3427
Merged
ymichael merged 10 commits intoSep 10, 2026
Conversation
This reverts commit e42b5a88d54a940172c3e950c5db4749689bac3f.
This reverts commit b85a4b514cc0e6afde0b011ad68c87f5d6c9a487.
ymichael
deleted the
bb/investigate-slow-database-queries-thr_q9gitchu8i
branch
September 10, 2026 18:40
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.
Human comments
What was wrong
Several synchronous database paths read more event history or payload data than their results required: filtered high-water marks aggregated complete histories, open-turn recovery did not seek directly past interruption boundaries, request recovery repeated scans for requests from the same thread, and search loaded text before limiting matches. Destroyed-environment cleanup bounded rows but could rewrite megabytes in one batch. The timeline byte-budget helper also aggregated up to 2,001 payloads before potentially scanning them again.
What changed
Six separate fixes:
theThese are controlled warm benchmark medians from a private database snapshot or isolated fixtures, not deployed latency measurements. The original measurements preceded the removal of an experimental delta index; that index remains present in the benchmark snapshot. Detachment total work was 4.038 → 3.616 ms across 1 → 17 batches.
Rebased onto the snapshot-bound conversation-group pagination change in #3325. The byte-budget helper now serves only turn-summary detail expansion; main timeline pages no longer call it. A fresh comparison against main at the caller’s 4 MiB budget returned identical results in all six fixtures. An oversized 5,000-event window improved 2.667 → 1.717 ms, while a fitting 2,000-event window regressed 0.454 → 1.114 ms due to JavaScript iteration. Retained the early-stop behavior with this explicit tradeoff.
The net change has no checkpoint worker, schema/migration, server/daemon wire, CLI, or configuration changes.
How you verified
pnpm exec turbo run test typecheck --filter=@bb/db: 34 files, 481 tests passed; typecheck passed.pnpm exec turbo run test --filter=@bb/server -- test/services/threads/timeline test/services/threads/thread-runtime-display.test.ts test/services/database-maintenance-sweep.test.ts test/system/event-pruning.test.ts test/public/public-thread-data.test.ts test/public/public-thread-diagnostic-events.test.ts test/public/public-thread-timeline test/public/public-thread-search.test.ts: 20 files, 205 tests passed, including the new pagination and detail-expansion cases.pnpm exec turbo run build typecheck --filter=@bb/server: passed.git diff --check: passed. Rebase range comparison confirmed unchanged patches.