Repository navigation
perf: prune event history only for changed threads - #5124
Merged
Merged
Conversation
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
Idle event-history pruning repeatedly visited unchanged threads to find obsolete events. On the settled audit database, a pass used 39.289 ms of CPU even with no new work.
What changed
Track changed threads in a small
thread_pruning_workqueue and consume that queue during pruning. Event ingestion coalesces one pending marker per affected thread in the same transaction. Event-data rewrites and archive/unarchive mark the relevant policy work in application code. Cursor revisions preserve changes during an in-progress scan.One generated migration creates and bootstraps the queue and adds cursor revision tracking. No SQL triggers or events-table indexes are added. This PR contains only event pruning, independent of the other idle-sweep changes.
Measured idle CPU fell to 0.217 ms/pass (99.4% lower). The tradeoff is about 11–12 µs extra CPU per single-event ingestion transaction: roughly 10% more streaming ingestion CPU at 10/25/50 threads, and 5.4% more CPU for raw inserts batched 32 at a time. Harnesses and results are kept outside the repository.
How you verified
pnpm exec turbo run test --filter=@bb/db.pnpm exec turbo run test --filter=@bb/server -- test/system/thread-pruning-sweep.test.ts test/services/periodic-sweeps.test.ts.pnpm exec turbo run typecheck --filter=@bb/db --filter=@bb/server.pnpm start:worktreeserver: a real Codex turn through the BB CLI, history reload, UI and CLI archive/unarchive. Production storage insertion of 100 synthetic rate-limit snapshots queued work; the running server retained the newest snapshot, removed 99 obsolete rows, drained the queue, and preserved the assistant answer.