Skip to content

perf(sql-store): add a batch exec seam; proxy the queue capture Message - #259

Merged
prisis merged 3 commits into
alphafrom
advisor/232-sqlstore-batch-queue
Aug 1, 2026
Merged

prisis merged 3 commits into
alphafrom
advisor/232-sqlstore-batch-queue

Conversation

@prisis

@prisis prisis commented Aug 1, 2026

Copy link
Copy Markdown
Member

A single insert/patch on a .global() table with search-index + aggregate/rank companions cost a double-digit count of sequential Hyperdrive round trips. Adds an optional batch to the exec seam (atomic on D1, pipelined on Hyperdrive) routing the companion loops through it with a sequential fallback. Also: the queue capture harness re-shaped Message through a fixed property allowlist (dev-only divergence — unlisted properties read undefined) → now a Proxy forwarding everything except ack/retry.

Verified: sql-store 92, queue 40, codegen 973 (goldens byte-identical).

⚠ Wires D1 batch through codegen/emit-app.ts + a golden + examples/blog — merge-order vs #243/#244/#256.

🤖 Generated with Claude Code

prisis and others added 2 commits July 31, 2026 22:37
SqlExec only exposed all/run, so the search-index token insert, the
aggregate tally backfill, and the rank-tuple backfill each ran their
companion writes as one sequential run() per row/chunk -- a double-digit
count of round trips for a single write on a .global() table with a
search index plus aggregate/rank companions.

Add an optional SqlExec.batch, route those three loops through it with a
sequential fallback when absent, and implement it for D1 (client.batch,
genuinely atomic) and the Hyperdrive postgres/mysql adapters (concurrent
dispatch over the connection/pool, still non-atomic).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The queue capture harness rebuilt each delivered Message/MessageBatch as
a plain object literal exposing a fixed property allowlist (ack/attempts/
body/id/retry/timestamp for a message; ackAll/messages/queue/retryAll for
a batch). Any other property the real object carries read undefined with
capture on (dev, Studio Queues panel) but its real value with capture off
(prod) -- a dev-only divergence in the environment you debug in.

Wrap with a Proxy instead: ack/retry (and ackAll/retryAll) still route
through the disposition map, everything else forwards via Reflect.get
pinned to the real object as receiver, so an accessor invoked through the
proxy still runs against the genuine host instance.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@prisis, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 18258297-50cb-4640-9db9-660cd046a4fd

📥 Commits

Reviewing files that changed from the base of the PR and between 36421ad and 6c41833.

⛔ Files ignored due to path filters (6)
  • examples/blog/lunora/_generated/app.ts is excluded by !**/_generated/** and included by none
  • packages/codegen/__tests__/fixtures/simple/expected/_generated/app.ts is excluded by !**/_generated/**, !**/__tests__/** and included by packages/**
  • packages/hyperdrive/__tests__/global-dialect.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/queue/__tests__/dispatch.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/sql-store/__tests__/ctx-db.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
  • packages/sql-store/__tests__/search-layout.test.ts is excluded by !**/__tests__/**, !**/*.test.ts and included by packages/**
📒 Files selected for processing (7)
  • packages/codegen/src/emit-app.ts
  • packages/hyperdrive/src/global-exec.ts
  • packages/queue/src/dispatch.ts
  • packages/sql-store/src/ctx-db.ts
  • packages/sql-store/src/dialect.ts
  • packages/sql-store/src/search-layout.ts
  • packages/sql-store/src/sql-exec.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Thank you for confirming the Contributor License Agreement! 🙏

@codspeed

codspeed Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 36 untouched benchmarks
⏩ 225 skipped benchmarks1


Comparing advisor/232-sqlstore-batch-queue (6c41833) with alpha (a540991)2

Open in CodSpeed

Footnotes

  1. 225 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on alpha (d9791ea) during the generation of this report, so a540991 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@netlify

netlify Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for lunorash ready!

Name Link
🔨 Latest commit 6c41833
🔍 Latest deploy log https://app.netlify.com/projects/lunorash/deploys/6a6db537a6b04300080c02db
😎 Deploy Preview https://deploy-preview-259--lunorash.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

…sn't throw

The generated D1 exec captured database.batch as a standalone reference
before calling it. workerd's real D1Database.batch dereferences `this`,
so the detached call throws an illegal-invocation TypeError the first
time any D1-backed .global() table with a search/aggregate/rank index
runs its companion-backfill write, in prod and wrangler dev alike.
Call it as database.batch(...) instead, guarded by a typeof check.

Also make the SqlExec.batch contract honest: its statements must be
mutually independent, not ordered — the D1 impl runs them atomically
in order, but the Hyperdrive Postgres/MySQL impls already dispatch
them concurrently via Promise.all, which the old doc contradicted
(including a purge-then-insert example that would corrupt data on
Hyperdrive). Order-dependent writes belong in separate sequential
run() calls, which is what every current caller already does.

batch's return value was discarded by every caller, yet every
implementation fabricated a result array to satisfy the type (D1: a
hardcoded 0, Hyperdrive PG: same, MySQL: a real affectedRows map that
existed only for a test to assert). Typed batch as Promise<void> on
both SqlExec and SqlCtxExec and dropped the dead result construction
along with the now-unneeded no-invalid-void-type suppression.

Regenerated the codegen golden fixture and the blog example's
_generated/app.ts; the only delta in both is the receiver-safe batch
call.
@prisis
prisis merged commit 22e7248 into alpha Aug 1, 2026
41 of 44 checks passed
@prisis
prisis deleted the advisor/232-sqlstore-batch-queue branch August 1, 2026 10:56
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using our GitHub Discussions tab for questions.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 8, 2026

This branch was previously deployed

1 inactive deployment
benchmarks — 6c41833d Deployed Aug 1, 2026 by prisis via Benchmarks #1308
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant