Repository navigation
tml-2766: untangle authoring data from runtime target descriptors - #688
Conversation
|
Warning Review limit reached
More reviews will be available in 18 minutes and 14 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (13)
📝 WalkthroughWalkthroughThis PR writes esbuild metafiles beside bundle outputs, adds a CLI to analyze metafiles (reverse-import graph + shortest entry→target chains), and separates runtime-only target metadata while annotating helper/schema calls for bundler tree-shaking. ChangesBundle Analysis & Runtime Tree-Shaking
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested Reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
size-limit report 📦
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/3-targets/3-targets/sqlite/src/core/authoring.ts (1)
5-13: ⚡ Quick winTrim this block comment and point to the bundler docs instead.
This explanation is doing too much inline. Please keep a short invariant note here and link the canonical esbuild pure-annotation/tree-shaking docs instead of embedding the tool-behavior details in source.
As per coding guidelines, "Prefer links to canonical docs over long comments."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/3-targets/3-targets/sqlite/src/core/authoring.ts` around lines 5 - 13, Replace the long explanatory block above the temporalAuthoringPresets call with a short invariant note and a canonical-link to esbuild's pure-annotation/tree-shaking docs: keep a one-line comment that states why the call is marked pure (so esbuild can tree-shake the sqliteAuthoringFieldPresets/temporalAuthoringPresets path) and include a URL to esbuild's documentation instead of the detailed tool-behavior text; ensure the reference still mentions temporalAuthoringPresets and family-sql/control so intent is clear.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/3-targets/3-targets/sqlite/src/core/authoring.ts`:
- Around line 5-13: Replace the long explanatory block above the
temporalAuthoringPresets call with a short invariant note and a canonical-link
to esbuild's pure-annotation/tree-shaking docs: keep a one-line comment that
states why the call is marked pure (so esbuild can tree-shake the
sqliteAuthoringFieldPresets/temporalAuthoringPresets path) and include a URL to
esbuild's documentation instead of the detailed tool-behavior text; ensure the
reference still mentions temporalAuthoringPresets and family-sql/control so
intent is clear.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: b37b9426-2b46-49f5-9ff4-0d6632313d11
📒 Files selected for processing (12)
examples/bundle-size/scripts/bundle.tsexamples/bundle-size/scripts/why.tspackages/1-framework/0-foundation/contract/src/cross-reference.tspackages/2-sql/9-family/src/core/timestamp-now-generator.tspackages/3-targets/3-targets/postgres/src/core/authoring.tspackages/3-targets/3-targets/postgres/src/core/descriptor-meta-runtime.tspackages/3-targets/3-targets/postgres/src/core/descriptor-meta.tspackages/3-targets/3-targets/postgres/src/exports/runtime.tspackages/3-targets/3-targets/sqlite/src/core/authoring.tspackages/3-targets/3-targets/sqlite/src/core/descriptor-meta-runtime.tspackages/3-targets/3-targets/sqlite/src/core/descriptor-meta.tspackages/3-targets/3-targets/sqlite/src/core/runtime-target.ts
b2ba33e to
87cda35
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/2-sql/9-family/src/core/timestamp-now-generator.ts`:
- Around line 47-59: Shorten the long bundler note around the /*
`@__NO_SIDE_EFFECTS__` */ annotation to a concise Rollup/Rollup-family specific
remark (remove references to esbuild and the long walkthrough), state that the
annotation allows Rollup-style tree-shaking of a no-side-effect call, and add a
pointer to the canonical notation spec URL
(https://github.com/javascript-compiler-hints/compiler-notations-spec/blob/main/no-side-effects-notation-spec.md)
so readers can follow the authoritative definition; keep the actual /*
`@__NO_SIDE_EFFECTS__` */ comment in place and only replace the surrounding
explanatory block with the shorter Rollup-specific note.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: ff1947ba-05cc-48ef-a476-b7611e1d121c
📒 Files selected for processing (12)
examples/bundle-size/scripts/bundle.tsexamples/bundle-size/scripts/why.tspackages/1-framework/0-foundation/contract/src/cross-reference.tspackages/2-sql/9-family/src/core/timestamp-now-generator.tspackages/3-targets/3-targets/postgres/src/core/authoring.tspackages/3-targets/3-targets/postgres/src/core/descriptor-meta-runtime.tspackages/3-targets/3-targets/postgres/src/core/descriptor-meta.tspackages/3-targets/3-targets/postgres/src/exports/runtime.tspackages/3-targets/3-targets/sqlite/src/core/authoring.tspackages/3-targets/3-targets/sqlite/src/core/descriptor-meta-runtime.tspackages/3-targets/3-targets/sqlite/src/core/descriptor-meta.tspackages/3-targets/3-targets/sqlite/src/core/runtime-target.ts
✅ Files skipped from review due to trivial changes (1)
- packages/1-framework/0-foundation/contract/src/cross-reference.ts
🚧 Files skipped from review as they are similar to previous changes (9)
- examples/bundle-size/scripts/bundle.ts
- packages/3-targets/3-targets/postgres/src/core/authoring.ts
- packages/3-targets/3-targets/sqlite/src/core/authoring.ts
- packages/3-targets/3-targets/postgres/src/core/descriptor-meta.ts
- packages/3-targets/3-targets/postgres/src/core/descriptor-meta-runtime.ts
- packages/3-targets/3-targets/postgres/src/exports/runtime.ts
- examples/bundle-size/scripts/why.ts
- packages/3-targets/3-targets/sqlite/src/core/descriptor-meta-runtime.ts
- packages/3-targets/3-targets/sqlite/src/core/runtime-target.ts
Persist each bundle’s esbuild metafile alongside the .mjs/.gz output and add scripts/why.ts, a metafile reverse-graph BFS that traces the shortest import path from an entry point to a given input substring. Used to diagnose the bundle-size regression closed by TML-2766: the metafiles surface the actual top inputs, and why.ts pinpoints the import chain that drags each unwanted module into a target’s runtime closure. Kept as a permanent investigative tool so future bundle-size investigations can reuse the same workflow. Signed-off-by: Serhii Tatarintsev <[email protected]>
…L-2766) Add packages/3-targets/3-targets/postgres/src/core/descriptor-meta-runtime.ts carrying only the identifiers + capabilities the runtime plane reads (kind/familyId/targetId/id/version/capabilities + the __codecTypes phantom). Refactor descriptor-meta.ts to compose from that base and add the authoring slot on top. Re-point exports/runtime.ts at the new runtime-safe meta; exports/control.ts and exports/pack.ts continue to import the full meta and remain shape-compatible. The runtime descriptor never read descriptor.authoring.*; only assembleAuthoringContributions (control plane) and the PSL interpreter do. Spreading the full meta into the runtime export was dragging @prisma-next/family-sql/control (and its sibling verify-sql-schema chunk) into the runtime closure for no runtime benefit. With the split, the runtime entry’s reachability graph is genuinely free of ./authoring, so the bundler can drop the control-plane modules. External shape and name (postgresTargetDescriptorMeta) are preserved. Signed-off-by: Serhii Tatarintsev <[email protected]>
…2766) Mirror of the postgres split. Add core/descriptor-meta-runtime.ts carrying only the identifiers + capabilities the runtime plane reads (kind/familyId/targetId/id/version/capabilities + the __codecTypes phantom). Refactor core/descriptor-meta.ts to compose from that base and add the authoring slot on top (sqlite’s authoring slot only carries field). Re-point core/runtime-target.ts at the runtime-safe meta; core/control-target.ts and exports/pack.ts continue to import the full meta unchanged. External shape and name (sqliteTargetDescriptorMeta) are preserved. Signed-off-by: Serhii Tatarintsev <[email protected]>
…haking (TML-2766)
Annotate both the outer blindCast(...) and the inner type({...}) call with
/* @__PURE__ */. arktype does not declare sideEffects: false, so without
these hints any consumer of @prisma-next/contract/types pulls the full
@ark/schema runtime — including type-only consumers, since the barrel
re-exports CrossReferenceSchema as a value alongside the types.
Both annotations are required. The inner annotation lets the bundler drop
the type({...}) call when blindCast(...) is unreferenced; without it, the
outer call can be dropped but type(...) would remain, dragging @ark/schema
with it.
The annotations are pure comments and do not affect runtime behaviour for
consumers that do reference CrossReferenceSchema — they still receive a
constructed schema.
Signed-off-by: Serhii Tatarintsev <[email protected]>
…or tree-shaking (TML-2766)
Annotate the `temporalAuthoringPresets` function declaration in
packages/2-sql/9-family/src/core/timestamp-now-generator.ts with
/* @__NO_SIDE_EFFECTS__ */. tsdown preserves the annotation through to
family-sql/dist/timestamp-now-generator-*.mjs (verified), so any rolldown
or esbuild consumer that reads the function declaration sees the marker.
Fallback after NSE-on-definition turned out to be ineffective at the
final esbuild bundling step: esbuild does propagate /* @__PURE__ */ on
call expressions but does NOT honour @__NO_SIDE_EFFECTS__ on imported
function declarations (rolldown/rollup do — that mismatch is what bit
the bundle measurement in R1). The fallback per-call-site annotation in
postgres/src/core/authoring.ts and sqlite/src/core/authoring.ts marks
each top-level temporalAuthoringPresets({...}) call pure at the consumer
end, which esbuild does respect.
With the call expressions marked pure and the call sites unreachable
from the runtime entry (per the R1 descriptor split), esbuild drops the
whole authoring chunk from the runtime closure:
* family-sql/dist/control.mjs — 67.8 KiB in inputs / 0 bytes in output
* family-sql/dist/verify-sql-schema — 43.2 KiB in inputs / 0 bytes in output
The metafile still records the modules as touched (esbuild keeps dead
imports in the input graph) but their bytesInOutput is zero. Result:
postgres emit minified drops from 445.7 KiB baseline to 371.7 KiB
(74.0 KiB drop). The remaining gap to the 365 KiB AC is occupied
entirely by @ark/schema/* (~80 KiB in output) coming in via
sql-orm-client → contract/types → arktype, which is Sibling B and
deferred to a follow-up Linear ticket.
Signed-off-by: Serhii Tatarintsev <[email protected]>
…766) The diff in `examples/bundle-size/scripts/` (metafile emission + why.ts tracer) is internal tooling for the bundle-size example. No consumer-facing API changed; `changes: []` is the explicit record per the record-upgrade-instructions skill. Signed-off-by: Serhii Tatarintsev <[email protected]>
Summary
Restores the invariant that a targets runtime descriptor carries only metadata the runtime plane reads. Drops 74.0 KiB raw / 17.3 KiB gzipped from the
examples/bundle-sizepostgres emit-minified bundle (445.7 → 371.7 KiB raw, 125.3 → 108.0 KiB gzipped).Fixes TML-2766.
What changed
postgresTargetDescriptorMetaandsqliteTargetDescriptorMetawere silently carrying anauthoring: { type, field, entityTypes }slot — control-plane data read at contract-construction time, never at runtime. The runtime export was spreading the same constant pack + control did, pullingauthoring.ts→temporalAuthoringPresetsfrom@prisma-next/family-sql/control→verify-sql-schema-*.mjsinto the runtime closure for no benefit.For postgres and sqlite:
descriptor-meta-runtime.tscarries only runtime-safe metadata (kind/familyId/targetId/id/version/capabilities+ the__codecTypesphantom).descriptor-meta.tscomposes runtime-safe base +authoringslot; same exported name + shape, so pack + control consumers dont change.The architectural invariant survives at the source level. Rolldowns auto-chunker then merged
authoring.tsanddescriptor-meta-runtime.tsinto a single dist chunk anyway (they share a reachability set viadescriptor-meta.ts), defeating the source-level split at the dist level. To close the loop at the bundler level:temporalAuthoringPresetsin@prisma-next/family-sql/src/core/timestamp-now-generator.tsgets/* @__NO_SIDE_EFFECTS__ */on the function definition.authoring.tsget per-call-site/* @__PURE__ */(esbuild ignores NSE on imported function declarations; the per-call annotation is what actually closes the chain at the examples bundling step).@prisma-next/contractsCrossReferenceSchemainitializer gets/* @__PURE__ */on bothblindCast(...)andtype({...})— pure tidying. No measurable bundle effect today because arktypes all-or-nothing module-init keeps the@ark/schemagraph alive through other workspace importers, but the annotation is a true statement and harmless to keep.Tooling
examples/bundle-size/scripts/bundle.tsnow persists esbuild metafiles next to each artifact;examples/bundle-size/scripts/why.tsis a new metafile reverse-graph BFS tracer.Out of scope
@ark/schema/*graph (~150 KiB) still in the postgres bundle. Removing it would require closing every runtime-reachable workspace importer ofimport { type } from "arktype"simultaneously (arktypestypefactory is a module-init-time singleton that touches the whole schema graph; partial closure achieves nothing). Separate architectural decision: does the SQL runtime need arktype validation on hot paths at all?sql-orm-clientfrom the postgres factory (155.8 KiB). Behavioural change to the public runtime surface, separate design call.Verification
pnpm typecheckworkspace-wide: clean.pnpm lint:deps: clean.pnpm test:packagesfor@prisma-next/{target-postgres,target-sqlite,contract,family-sql}: green.examples/bundle-sizepnpm testpostgres path: green (mongo env-blocked on local NixOS host).Note on lint: per-package biome lint is env-blocked on the local NixOS development host (biomes linux-arm64 binary, NixOS dynamic linker incompatibility).
pnpm lintgate must be re-verified in CI before merge.Summary by CodeRabbit
New Features
Chores