perf(db, schema): enable prepared statements and optimize parse path#1749
Merged
viniciusdacal merged 1 commit intomainfrom Mar 23, 2026
Merged
perf(db, schema): enable prepared statements and optimize parse path#1749viniciusdacal merged 1 commit intomainfrom
viniciusdacal merged 1 commit intomainfrom
Conversation
Enable `{ prepare: true }` on postgres.js `sql.unsafe()` calls in
@vertz/db's postgres driver. This enables server-side prepared statement
caching, reducing per-query overhead by ~60% (0.57ms → 0.24ms/op).
Remove the manual `coerceValue` timestamp coercion layer — postgres.js
handles type conversion natively via built-in OID parsers when connected
normally.
In @vertz/schema, optimize the hot parse path:
- Memoize shape keys Set in ObjectSchema constructor (avoid per-parse alloc)
- Lazy issues array in ParseContext (skip alloc for valid parses)
- Skip unknown key filtering in strip mode (the default)
Benchmarked via rinha-de-backend URL shortener challenge: Vertz achieved
2443 req/s (#1) vs Go 1528 req/s (#2), with p95 latency of 54ms vs 79ms.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
viniciusdacal
added a commit
that referenced
this pull request
Mar 24, 2026
- Add domain() API guide page with route prefixing, middleware, collision detection - Add composite primary keys section to schema guide - Add form field revalidation (revalidateOn) to forms guide and API reference - Update SSR guide from two-pass to single-pass rendering flow - Add RLS migration integration and withSessionVars() to migrations and codegen guides - Document rules.where() database-level enforcement in auth guide - Add prepared statements section to queries guide - Update navigation and server overview for domains Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
viniciusdacal
added a commit
that referenced
this pull request
Mar 24, 2026
…ngle-pass) (#1778) * docs: audit and update docs for recent PRs (#1749-#1773) - Add domain() API guide page with route prefixing, middleware, collision detection - Add composite primary keys section to schema guide - Add form field revalidation (revalidateOn) to forms guide and API reference - Update SSR guide from two-pass to single-pass rendering flow - Add RLS migration integration and withSessionVars() to migrations and codegen guides - Document rules.where() database-level enforcement in auth guide - Add prepared statements section to queries guide - Update navigation and server overview for domains Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: fix review findings — FieldState accuracy, withSessionVars, CLI commands - Fix FieldState API reference: remove phantom pristine/setTouched/validate, add actual setValue/reset methods - Replace withSessionVars() import examples with raw SET LOCAL SQL since the function is not yet part of the public API - Fix vertz generate → vertz codegen CLI command references in codegen guide Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
{ prepare: true }onsql.unsafe()in@vertz/dbpostgres driver — enables server-side prepared statement caching, reducing per-query overhead by ~60% (0.57ms → 0.24ms/op)coerceValuetimestamp coercion — postgres.js handles type conversion natively via built-in OID parsers@vertz/schemaparse hot path: memoize shape keys Set, lazy issues array, skip unknown key filtering in strip mode (the default)Benchmark Results (rinha-de-backend URL shortener challenge)
Vertz beats Go by 60% on throughput and 31% on latency.
What changed
@vertz/dbpostgres driversql.unsafe()now passes{ prepare: true }— postgres.js caches query plans server-side, avoiding parse+plan on every callcoerceValue()/isTimestampString()— these ran a regex on every column of every row to convert timestamp strings to Dates. Withfetch_types: false, postgres.js still handles standard type conversion natively. The regex coercion was unnecessary overhead with false-positive risk (text columns containing timestamp-like strings would be silently converted)@vertz/schemaparse context + object schemaParseContext.issuesis now lazily allocated — the empty[]array was allocated on every successful parse (the 99% case), wastedObjectSchema._shapeKeysSet is memoized in the constructor instead of recreated per.parse()callstripmode (the default) — previously computed the list of unknown keys then threw it awayTest plan
{ prepare: true })Related
@vertz/dbqueries🤖 Generated with Claude Code