Skip to content

Improve Schema type-level performance - #2442

Merged
gcanti merged 19 commits into
mainfrom
schema-lazy-bottom
Jun 21, 2026
Merged

Improve Schema type-level performance#2442
gcanti merged 19 commits into
mainfrom
schema-lazy-bottom

Conversation

@gcanti

@gcanti gcanti commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

OpenAI Generated smoke test, measured against main:

Total instantiations
main:     2,115,660
current:    973,683
delta:   -1,141,977 (-54.0%)

Baseline-adjusted:

Schema import baseline
main:       659,062
current:    532,656

Generated schema marginal cost
main:     1,456,598
current:    441,027
delta:   -1,015,571 (-69.7%)

Short version: compiling packages/ai/openai/src/Generated.ts now uses ~54% fewer total type instantiations vs main. If we subtract the fixed cost of importing Effect/Schema, the generated schema code itself is down ~70%.

@changeset-bot

changeset-bot Bot commented Jun 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 683c865

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 27 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

File Name Current Size Previous Size Difference
basic.ts 6.58 KB 6.58 KB 0.00 KB (0.00%)
batching.ts 9.09 KB 9.09 KB 0.00 KB (0.00%)
brand.ts 6.14 KB 6.14 KB 0.00 KB (0.00%)
cache.ts 9.79 KB 9.79 KB 0.00 KB (0.00%)
config.ts 18.74 KB 18.80 KB -0.07 KB (-0.36%)
differ.ts 16.81 KB 16.81 KB -0.00 KB (-0.01%)
http-client.ts 20.34 KB 20.34 KB 0.00 KB (0.00%)
logger.ts 10.12 KB 10.12 KB 0.00 KB (0.00%)
metric.ts 8.42 KB 8.42 KB 0.00 KB (0.00%)
optic.ts 7.35 KB 7.35 KB 0.00 KB (0.00%)
pubsub.ts 13.89 KB 13.89 KB 0.00 KB (0.00%)
queue.ts 10.98 KB 10.98 KB 0.00 KB (0.00%)
schedule.ts 10.19 KB 10.19 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 3.49 KB 3.49 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 26.80 KB 26.81 KB -0.00 KB (-0.01%)
schema-string-transformation.ts 12.48 KB 12.48 KB 0.00 KB (0.00%)
schema-string.ts 10.18 KB 10.18 KB 0.00 KB (0.00%)
schema-template-literal.ts 14.05 KB 14.05 KB +0.00 KB (+0.01%)
schema-toArbitraryLazy.ts 20.47 KB 20.47 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 21.04 KB 21.04 KB -0.00 KB (-0.01%)
schema-toCodecJson.ts 17.62 KB 17.62 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 17.52 KB 17.52 KB +0.00 KB (+0.02%)
schema-toFormatter.ts 17.37 KB 17.37 KB -0.00 KB (-0.02%)
schema-toJsonSchemaDocument.ts 19.93 KB 19.93 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 17.91 KB 17.92 KB -0.01 KB (-0.03%)
schema.ts 16.95 KB 16.95 KB -0.00 KB (-0.01%)
stm.ts 11.87 KB 11.87 KB 0.00 KB (0.00%)
stream.ts 9.20 KB 9.20 KB 0.00 KB (0.00%)

@gcanti
gcanti force-pushed the schema-lazy-bottom branch from a0e7fe0 to ac941f2 Compare June 20, 2026 15:34
@gcanti
gcanti marked this pull request as ready for review June 21, 2026 12:59
@gcanti gcanti changed the title Add Schema.BottomLazy and use it for schema combinators that compute several independent public views Improve Schema type-level performance Jun 21, 2026
@gcanti
gcanti merged commit 7e1f455 into main Jun 21, 2026
14 checks passed
@gcanti
gcanti deleted the schema-lazy-bottom branch June 21, 2026 15:49
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.

1 participant