8000 perf: prepare postgres.js statements so a run takes one round trip by colinhacks · Pull Request #107 · colinhacks/reylo · GitHub
[go: up one dir, main page]

Skip to content

perf: prepare postgres.js statements so a run takes one round trip - #107

Merged
colinhacks merged 2 commits into
mainfrom
pg-prepare
Oct 24, 2026
Merged

colinhacks merged 2 commits into
mainfrom
pg-prepare

Conversation

@colinhacks
Copy link
Copy Markdown
Owner

postgres.js's unsafe() prepares nothing by default (prepare: false), and for a query with parameters it then sends Parse and Describe, waits for the answer, and only then sends Bind and Execute. Every .run() on a postgres.js client therefore took two round trips, on every run. Reylo now passes { prepare: true }, so the statement is prepared on the connection the first time and each later run takes one round trip, as postgres.js's own tagged queries do.

A client created with prepare: false, as one behind a pooler in transaction mode is, still prepares nothing: postgres.js takes the client's option over the query's (q.prepare = options.prepare && … in connection.js). A query without parameters still goes over the simple protocol, as before. Bun.sql, which prepares by itself, is unchanged.

Measured locally through a proxy adding 5 ms to each round trip, select id, name from users where id = $1::int:

median
unsafe(text, [1]), before 12.6 ms
unsafe(text, [1], { prepare: true }), after 6.8 ms (first run 14.8 ms)
after, on a client created with prepare: false 13.0 ms

What it touches:

  • Transactions, savepoints, reserved connections and Drizzle over postgres.js all take unsafe(text, args, options); a wrapper of postgres.js's shape ignores the extra argument.
  • A prepared statement whose result type a migration changed (a select * whose table gained a column) fails its next run with cached plan must not change result type; postgres.js prepares it again and retries, transparently outside a transaction. Inside a transaction the retry cannot run, so that run fails once on that connection, exactly as postgres.js's own queries do. The freshness check is unchanged: it still fails a call whose columns changed.

Tests: tests/execute.test.ts checks the option is passed to postgres.js and not to Bun.sql, and on a live server reads pg_prepared_statements on a reserved connection after two runs: one statement run twice on a default client, none on a client created with prepare: false, and the same statement reused inside sql.begin. The driver matrix's postgres.js and Drizzle-over-postgres.js jobs (209 rows) match RESULTS.md.

The postgres page and the agent skill say that Reylo's queries are prepared on postgres.js, and that a client behind a pooler in transaction mode takes prepare: false.

Copilot AI balanced review requested due to automatic review settings October 24, 2026 01:47
@vercel
vercel Bot commented Oct 24, 2026 •
Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
reylo Ready Ready Preview Oct 24, 2026 1:50am UTC

Request Review

@pullfrog
pullfrog Bot commented Oct 24, 2026 •
Copy link
Copy Markdown
Contributor

No configured credential can serve this run. Your Claude Pro/Max subscription has hit its usage limit, which resets at 2026-10-26 08:00 UTC. Re-trigger after it resets, or add an API key for this provider, which Pullfrog falls back to automatically.

The providers' responses
CLAUDE_CODE_OAUTH_TOKEN: 429: This request would exceed your account's rate limit. Please try again later.

Pick another model →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using claude-opus-5-5

Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@colinhacks
colinhacks merged commit 3246430 into main Oct 24, 2026
6 of 7 checks passed
@colinhacks
colinhacks deleted the pg-prepare branch October 24, 2026 01:51
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.

2 participants

0