perf(core): walk each schema and operation once in a node-outer generate loop - #3829
Merged
Conversation
…ate loop `#runGenerators` looped plugin-outer, re-traversing the shared `schemas` and `operations` arrays once per plugin so the walk cost was `plugins × nodes`. Invert it to node-outer: each schema is visited once and each operation once, and the node fans out to the matching generators of every plugin in dependency order. Each node carries a `NodeCache`, a per-node object shared by every plugin that generates from it, reachable through `ctx.cache`, so work derived only from the node is computed once and reused. The type is exported from `@kubb/core` and `@kubb/kit`. Output is unchanged: schemas still run before operations, plugins in dependency order, macros and include/exclude/override filters still apply before a plugin's generators run, and the `operations` batch still fires once per plugin after the operation walk. `kubb:plugin:end` and the timing diagnostics still count up in plugin order. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D1JYweapPQQNnjvkLV6c7n
🦋 Changeset detectedLatest commit: 864bdf0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
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 |
@kubb/adapter-oas
@kubb/ast
@kubb/cli
@kubb/core
@kubb/kit
kubb
@kubb/mcp
@kubb/parser-md
@kubb/parser-ts
@kubb/plugin-barrel
@kubb/renderer-jsx
unplugin-kubb
commit: |
Trim the per-plugin state comment that restated the object's fields, and simplify the changeset so it reads plainly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01D1JYweapPQQNnjvkLV6c7n
Contributor
|
Size Change: 0 B Total Size: 409 kB ℹ️ View Unchanged
|
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.
🎯 Changes
Closes #3812.
#runGeneratorslooped plugin-outer, so it re-traversed the sharedschemasandoperationsarrays once per plugin and paid the macro and option resolution walkplugins × nodestimes. This inverts the loop to node-outer: each schema is visited once and each operation once, and the node fans out to the matching generators of every plugin in dependency order.Each node carries a
NodeCache, a per-node object shared by every plugin that generates from that same node, reachable throughctx.cache. Work derived only from the node can be filled once and read by the rest instead of recomputed per plugin. The type is exported from@kubb/coreand@kubb/kit, and theoperationsbatch call receives a fresh scratch cache since it spans every node rather than one. This is the shared cache the name/path, import, and parameter items on the generation-repetition roadmap hang off.Output is unchanged, which the constraints below preserve:
operationsbatch still fires once per plugin after the single operation walk.kubb:plugin:endand the timing diagnostics still count up in dependency order for the CLI'sPlugins N/Mline.Files
packages/core/src/nodeCache.ts— newNodeCachetype andcreateNodeCachefactory (get/set/getOrSet).packages/core/src/KubbDriver.ts— node-outer#runGenerators, per-node cache wired into each generator context.packages/core/src/defineGenerator.ts—cachefield onGeneratorContext.packages/core/src/{types.ts,mocks.ts}andpackages/kit/src/index.ts— export the type and provide a cache in the mocked context.✅ Checklist
pnpm run test.Unit coverage:
KubbDriver.test.tsnow asserts the node-outer fan-out order and that one cache is shared per node across plugins while each node gets a fresh one;nodeCache.test.tscovers the cache primitive.pnpm lintand@kubb/core/@kubb/kittypecheck are clean. The one failing test in the suite (packages/mcp/src/tools/generate.test.ts) fails on the base branch too, from a missing built@kubb/adapter-oasdist in this environment, unrelated to this change.🚀 Release Impact
🤖 Generated with Claude Code
https://claude.ai/code/session_01D1JYweapPQQNnjvkLV6c7n
Generated by Claude Code