Skip to content

refactor(opencode): cache compaction boundary to skip redundant DB reads#22207

Closed
tobias-weiss-ai-xr wants to merge 1 commit intoanomalyco:devfrom
tobias-weiss-ai-xr:perf/incremental-message-loading
Closed

refactor(opencode): cache compaction boundary to skip redundant DB reads#22207
tobias-weiss-ai-xr wants to merge 1 commit intoanomalyco:devfrom
tobias-weiss-ai-xr:perf/incremental-message-loading

Conversation

@tobias-weiss-ai-xr
Copy link
Copy Markdown

@tobias-weiss-ai-xr tobias-weiss-ai-xr commented Apr 12, 2026

Fixes #22208

What

filterCompactedEffect reads all messages from DB every loop step, then discards pre-compaction ones. For 500 messages (300 pre-compaction), that's ~10 SQL queries per iteration when only ~4 are needed.

How

  • Added since parameter to page()/stream() — adds WHERE clause to skip older messages
  • Cache compaction boundary per session (bounded Map, max 1000, FIFO eviction)
  • Invalidate cache when new compaction is created

Verification

  • bun run typecheck — 19 packages clean
  • bun test test/provider/transform.test.ts — 131 pass
  • Inspected SQL output to confirm correct WHERE clause with since

@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title perf: skip re-reading pre-compaction messages from DB every loop step doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 12, 2026
@tobias-weiss-ai-xr tobias-weiss-ai-xr changed the title perf: skip re-reading pre-compaction messages from DB every loop step refactor(opencode): cache compaction boundary to skip redundant DB reads Apr 12, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 13, 2026
@github-actions github-actions bot closed this Apr 13, 2026
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.

perf: session loop re-reads all messages from DB every iteration

1 participant