Skip to content

perf(*): about 15% faster overall in large sdk codegen#4189

Merged
mrlubos merged 16 commits into
hey-api:mainfrom
SukkaW:printter-optimization
Jul 1, 2026
Merged

perf(*): about 15% faster overall in large sdk codegen#4189
mrlubos merged 16 commits into
hey-api:mainfrom
SukkaW:printter-optimization

Conversation

@SukkaW

@SukkaW SukkaW commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

The PR follows my previous PR #3823 and #3917

  • Reduce ts-compiler print GC pressure by reducing object allocation: reduce spread copy, remove context object. Also, some other micro-optimizations like the faster join method.
  • Cache graph generation to reduce potential repeated calculations
  • Avoid repeated stub key population in Symbol registry
  • Improve pointer dependencies collection
  • Hoist visitor/walker for validation plugin (zod/valibot) to re-use instances
  • Re-use the processor instance for the TypeScript plugin
  • Improve walking minHeap implementation
  • Some early bailout for regex testing (as regex is expensive)
  • Micro optimization for escaping: I learned this technique back when I created fast-escape-html and fast-escape-regexp
  • Other micro-optimizations (replace forEach w/ plain loop, reduce closure, and more)

The PR also introduces extra phase timing tracking with debug log level, with detailed generation step time:

image

The Cloudflare schema generation time reduces from 10-11 seconds to 9-10 (sometimes sub-9 seconds if the download is very fast) seconds.

Also, FlameGraph comparison:

before:

image

after:

image

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@pullfrog

pullfrog Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Rerun failed job ➔View workflow run | via Pullfrog | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

@SukkaW is attempting to deploy a commit to the Hey API Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot

changeset-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b84d40f

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

This PR includes changesets to release 4 packages
Name Type
@hey-api/codegen-core Patch
@hey-api/shared Patch
@hey-api/openapi-python Patch
@hey-api/openapi-ts 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

@SukkaW SukkaW changed the title perf(*): 15% faster overall sdk codegen perf(*): about 15% faster overall in large sdk codegen Jul 1, 2026
@codecov

codecov Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.64688% with 90 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.60%. Comparing base (c1bae1d) to head (b84d40f).

Files with missing lines Patch % Lines
packages/openapi-ts/src/ts-compiler/printer.ts 82.89% 65 Missing and 6 partials ⚠️
packages/shared/src/openApi/shared/utils/graph.ts 89.55% 6 Missing and 1 partial ⚠️
...ges/openapi-ts/src/plugins/valibot/v1/processor.ts 0.00% 2 Missing ⚠️
...kages/openapi-ts/src/plugins/zod/mini/processor.ts 0.00% 2 Missing ⚠️
...ackages/openapi-ts/src/plugins/zod/v3/processor.ts 0.00% 2 Missing ⚠️
...ackages/openapi-ts/src/plugins/zod/v4/processor.ts 0.00% 2 Missing ⚠️
packages/shared/src/graph/walk.ts 96.66% 1 Missing and 1 partial ⚠️
packages/openapi-python/src/py-compiler/printer.ts 96.29% 1 Missing ⚠️
.../shared/src/openApi/shared/transforms/readWrite.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4189      +/-   ##
==========================================
+ Coverage   40.16%   40.60%   +0.44%     
==========================================
  Files         828      828              
  Lines       25358    25620     +262     
  Branches     7552     7628      +76     
==========================================
+ Hits        10184    10402     +218     
- Misses      12237    12277      +40     
- Partials     2937     2941       +4     
Flag Coverage Δ
unittests 40.60% <86.64%> (+0.44%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Jul 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

@hey-api/codegen-cli

npm i https://pkg.pr.new/@hey-api/codegen-cli@4189

@hey-api/codegen-core

npm i https://pkg.pr.new/@hey-api/codegen-core@4189

@hey-api/json-schema-ref-parser

npm i https://pkg.pr.new/@hey-api/json-schema-ref-parser@4189

@hey-api/nuxt

npm i https://pkg.pr.new/@hey-api/nuxt@4189

@hey-api/openapi-python

npm i https://pkg.pr.new/@hey-api/openapi-python@4189

@hey-api/openapi-ts

npm i https://pkg.pr.new/@hey-api/openapi-ts@4189

@hey-api/shared

npm i https://pkg.pr.new/@hey-api/shared@4189

@hey-api/spec-types

npm i https://pkg.pr.new/@hey-api/spec-types@4189

@hey-api/types

npm i https://pkg.pr.new/@hey-api/types@4189

@hey-api/vite-plugin

npm i https://pkg.pr.new/@hey-api/vite-plugin@4189

commit: b84d40f

@SukkaW SukkaW force-pushed the printter-optimization branch from c321769 to 6e7c933 Compare July 1, 2026 18:06
@mrlubos mrlubos merged commit 508e443 into hey-api:main Jul 1, 2026
12 of 13 checks passed
@hey-api hey-api Bot mentioned this pull request Jul 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