Skip to content

perf(sqlite): add indexes for hot query paths - #248

Merged
benvinegar merged 1 commit into
mainfrom
perf/sqlite-hot-path-indexes
Aug 11, 2026
Merged

perf(sqlite): add indexes for hot query paths#248
benvinegar merged 1 commit into
mainfrom
perf/sqlite-hot-path-indexes

Conversation

@benvinegar

@benvinegar benvinegar commented Aug 11, 2026

Copy link
Copy Markdown
Member

Summary

SQLite-backed workspaces currently scan and sort entire tables for several common reads. This adds six targeted indexes for:

  • posts within a session, ordered by creation time
  • recently updated posts
  • incremental session comments and post threads
  • comment lookup and deletion by ID
  • assets belonging to a session

The indexes are created with IF NOT EXISTS after legacy schema migrations, so existing Durable Objects and local databases upgrade safely on first startup.

Performance

Synthetic in-memory SQLite benchmark with 100,000 posts, 200,000 comments, and 50,000 assets; values are medians from 30 warm runs:

Query Before After Speedup
Session posts 2.657 ms 0.661 ms 4.0×
Recent posts 16.292 ms 0.015 ms 1,061×
Post counts by session 11.987 ms 2.343 ms 5.1×
Session comments 2.609 ms 0.693 ms 3.8×
Post comments 2.019 ms 0.008 ms 259×
Comment by ID 3.846 ms 0.002 ms 2,284×
Session assets 1.395 ms 0.450 ms 3.1×

Building all six indexes took 124 ms in this synthetic in-memory database. Existing databases pay this construction cost once after upgrading.

Testing

  • Added coverage for upgrading an existing unindexed workspace and repeated initialization.
  • Added query-plan assertions for each optimized production query.
  • Passed unit tests, coverage, typechecks, lint, formatting, Worker integration, security audit, Chromium/WebKit E2E, CodeQL, and Socket checks.
  • Independent review found no blockers.

This PR description was generated by Pi using GPT-5.6 Sol

@benvinegar benvinegar changed the title perf(sqlite): index hot workspace queries perf(sqlite): add indexes for hot query paths Aug 11, 2026
@benvinegar
benvinegar merged commit f15dc13 into main Aug 11, 2026
9 checks passed
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