Skip to content

Optimize slow event queries and incremental vacuum - #1716

Merged
ymichael merged 1 commit into
mainfrom
bb/investigate-slow-database-query-thr_84bqj7akge
Aug 17, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/investigate-slow-database-query-thr_84bqj7akge

Conversation

@ymichael

@ymichael ymichael commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • add a partial covering index for timeline parent-crossing lookups
  • aggregate background-task lifecycle state in one indexed scan
  • remove full dbstat scans from incremental vacuum passes
  • add migration, query-plan regressions, and maintenance coverage

Local database benchmark

Benchmarked against an isolated online-backup copy of the 1.35 GiB local database:

  • index migration: 3.231 seconds; 800 KiB; no database-file growth because it reused freelist pages
  • parent crossing: 436 ms to 0.437 ms on the first run
  • background-task aggregation: 199 ms to 0.91 ms on the first run, with identical results
  • incremental vacuum: 5,007 ms to 29.8 ms while reclaiming the same pages

The live source database was opened read-only and was not migrated or modified.

Validation

  • pnpm exec turbo run typecheck --filter=@bb/db
  • pnpm exec turbo run typecheck --filter=@bb/server
  • pnpm exec turbo run test --filter=@bb/db --force (387 tests)
  • pnpm exec turbo run test --filter=@bb/server --force (1,693 tests)
  • migration repair/replay and SQLite query-plan regression tests

AGENT GENERATED: by GPT-5


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@bb-slop-cop

bb-slop-cop Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am SlopCop, and I am reviewing this pull request now. I will check security, code quality, architecture, duplicate code, performance, and tests.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

Plain English summary

This change makes three database jobs faster. It adds a small index for parent checks. It combines two background-task scans. It also removes full-database reads from routine incremental vacuum work.

Review result

I found no blocking or non-blocking defects.

  • Security: The SQL uses fixed internal values. The migration keeps transaction and rollback protection.
  • Code quality: The new result type matches all callers. The tests cover query plans, migration behavior, and vacuum results.
  • Architecture: The changes stay in the database package. I found no duplicate code or useful refactor.
  • Performance: Real-data checks showed large read gains. The new index added a small write cost for tool-call rows only.
  • Validation: All 387 database tests passed. The database type check passed. Relevant timeline tests passed. All current GitHub CI checks passed.
  • Browser test: I did not run one because this change has no user-interface route.

The final independent review gate returned APPROVE. I posted this as a comment-only review.

@ymichael
ymichael merged commit 22b1151 into main Aug 17, 2026
11 checks passed
@ymichael
ymichael deleted the bb/investigate-slow-database-query-thr_84bqj7akge branch August 17, 2026 22:04
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