Skip to content

Fast-path canonical PostgreSQL dates - #30187

Closed
StevenMcClankerton wants to merge 2 commits into
optimize-decode-runtimefrom
optimize-decode-postgres-date
Closed

Fast-path canonical PostgreSQL dates#30187
StevenMcClankerton wants to merge 2 commits into
optimize-decode-runtimefrom
optimize-decode-postgres-date

Conversation

@StevenMcClankerton

@StevenMcClankerton StevenMcClankerton commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Linked issue

n/a — performance work without a tracking issue

Prerequisite: #30186.

Summary

Fast-paths the canonical PostgreSQL YYYY-MM-DD wire form with direct Temporal.PlainDate construction while retaining the existing parser for every noncanonical representation. On top of the runtime optimization PR, aggregate whole-result-set latency improves from 809.2 µs to 679.0 µs.

At a glance

return new Temporal.PlainDate(
  year0 * 1000 + year1 * 100 + year2 * 10 + year3,
  month0 * 10 + month1,
  day0 * 10 + day1,
);

Only fixed-width ASCII dates reach this constructor path.

Decision

Recognize and validate the ordinary server representation using character codes, then construct the immutable Temporal value directly. BC dates, expanded years, sentinels, malformed input, and other noncanonical forms continue through the existing adaptation and Temporal.PlainDate.from behavior.

Reviewer notes

  • Every digit is range-checked before direct construction; length and separator positions are fixed.
  • The generic fallback remains the source of behavior and errors outside the canonical form.
  • The touched helper also replaces Reflect.get with typed Symbol.toStringTag access while preserving the existing runtime guard, satisfying the production-code structural lint without changing wrong-type handling.

Behavior changes & evidence

Testing performed

  • pnpm --filter @internal/target-postgres test — 93 files, 1596 tests
  • pnpm --filter @internal/target-postgres typecheck
  • Rebuilt framework components, SQL relational core, PostgreSQL target, and SQL runtime before pnpm --filter benchmarks bench
  • Aggregate whole-result-set result: 809.2 µs → 679.0 µs (-16.1%); autoresearch best was 652.5 µs (-47.2% from baseline)

Skill update

n/a — internal codec implementation optimization with unchanged public behavior

Checklist

  • All commits are signed off (git commit -s) per the DCO.
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • Tests are updated.
  • The PR title is in TML-NNNN: <sentence-case title> form — no Linear ticket exists for this work.
  • The Skill update section above is filled in.

Notes for the reviewer

This is the final PR in the stack and contains only the PostgreSQL date-codec optimization plus the typed property-access cleanup required in the touched helper.

Alternatives considered

  • Continue using Temporal.PlainDate.from for canonical dates: simpler, but it dominates date-heavy result-set latency.
  • Regular-expression validation: rejected after a 4.6% aggregate regression versus character-code validation.
  • Bitwise digit-range aggregation: rejected because two-run performance was identical to straightforward scalar checks and readability was worse.
  • Cache decoded dates: rejected because changing object identity and retaining an unbounded value set would alter runtime characteristics.

Summary by CodeRabbit

  • Performance
    • Improved PostgreSQL date decoding for standard yyyy-mm-dd values.
    • Added validation for date components while enabling faster direct parsing.
    • Retained fallback handling for other supported date formats.
    • Date values now decode more efficiently without changing the supported behavior or output format.

@coderabbitai

coderabbitai Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Team

Run ID: cc06c02d-4ca1-401b-bd0b-18b6d1df05f1

📥 Commits

Reviewing files that changed from the base of the PR and between d20d3ba and 43b39a0.

📒 Files selected for processing (1)
  • packages/3-targets/3-targets/postgres/src/core/temporal-codec-helpers.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The PostgreSQL temporal codec now reads Symbol.toStringTag directly and fast-paths standard yyyy-mm-dd values before using Temporal.PlainDate.from.

Changes

PostgreSQL temporal codec

Layer / File(s) Summary
Temporal value encoding and date decoding
packages/3-targets/3-targets/postgres/src/core/temporal-codec-helpers.ts
The encoder input type accepts an optional Symbol.toStringTag property and reads it through direct property access. Date decoding validates standard date strings and constructs Temporal.PlainDate directly, with Temporal.PlainDate.from as the fallback.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 43b39

This localized PostgreSQL date-decoding optimization preserves fallback behavior for noncanonical inputs, and no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise, specific, and accurately describes the main change: adding a fast path for canonical PostgreSQL dates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch optimize-decode-postgres-date

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

@pkg-pr-new

pkg-pr-new Bot commented Sep 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

@prisma/orm-extension-arktype-json

npm i https://pkg.pr.new/@prisma/orm-extension-arktype-json@30187

@prisma/orm-extension-middleware-cache

npm i https://pkg.pr.new/@prisma/orm-extension-middleware-cache@30187

@prisma/orm-extension-paradedb

npm i https://pkg.pr.new/@prisma/orm-extension-paradedb@30187

@prisma/orm-extension-pgvector

npm i https://pkg.pr.new/@prisma/orm-extension-pgvector@30187

@prisma/orm-extension-postgis

npm i https://pkg.pr.new/@prisma/orm-extension-postgis@30187

@prisma/orm-extension-supabase

npm i https://pkg.pr.new/@prisma/orm-extension-supabase@30187

@prisma/orm-family-mongo

npm i https://pkg.pr.new/@prisma/orm-family-mongo@30187

@prisma/orm-family-sql

npm i https://pkg.pr.new/@prisma/orm-family-sql@30187

@prisma/orm-framework

npm i https://pkg.pr.new/@prisma/orm-framework@30187

@prisma/orm-mongo

npm i https://pkg.pr.new/@prisma/orm-mongo@30187

@prisma/orm-postgres

npm i https://pkg.pr.new/@prisma/orm-postgres@30187

@prisma/orm-sqlite

npm i https://pkg.pr.new/@prisma/orm-sqlite@30187

@prisma/orm-target-mongo

npm i https://pkg.pr.new/@prisma/orm-target-mongo@30187

@prisma/orm-target-postgres

npm i https://pkg.pr.new/@prisma/orm-target-postgres@30187

@prisma/orm-target-sqlite

npm i https://pkg.pr.new/@prisma/orm-target-sqlite@30187

@prisma/orm-toolchain

npm i https://pkg.pr.new/@prisma/orm-toolchain@30187

commit: 0380a6c

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
postgres / no-emit 175.52 KB (+0.11% 🔺)
postgres / emit 152.67 KB (+0.1% 🔺)
mongo / no-emit 101.09 KB (0%)
mongo / emit 90.95 KB (0%)
cf-worker / no-emit 199.43 KB (+0.08% 🔺)
cf-worker / emit 173.96 KB (+0.11% 🔺)

@SevInf
SevInf force-pushed the optimize-decode-runtime branch from aaef5ef to 707d55f Compare September 1, 2026 09:34
@SevInf
SevInf force-pushed the optimize-decode-postgres-date branch from d20d3ba to 375ca63 Compare September 1, 2026 09:59
Parse the ordinary YYYY-MM-DD wire form with digit arithmetic and construct Temporal.PlainDate directly while preserving the generic parser for BC, expanded-year, sentinel, and malformed values.

Metric: result_set_total_us 809.2us -> 679.0us (-16.1%).
Signed-off-by: Steven McClankerton <tatarintsev@prisma.io>
Signed-off-by: Steven McClankerton <tatarintsev@prisma.io>
@SevInf
SevInf force-pushed the optimize-decode-runtime branch from 104ddf4 to 4d0c91f Compare September 1, 2026 10:26
@SevInf
SevInf force-pushed the optimize-decode-postgres-date branch from 43b39a0 to 0380a6c Compare September 1, 2026 10:26
@SevInf SevInf closed this Sep 1, 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.

2 participants