Skip to content

perf(kit,nuxt): use lazy imports to improve parsing speed - #35901

Merged
danielroe merged 4 commits into
mainfrom
perf/lazy-imports
Jul 30, 2026
Merged

danielroe merged 4 commits into
mainfrom
perf/lazy-imports

Conversation

@danielroe

Copy link
Copy Markdown
Member

🔗 Linked issue

📚 Description

noticed when doing some perf testing that the cost of importing jiti and untyped/babel-plugin are considerable in terms of parsing, when they might not be needed

@danielroe
danielroe enabled auto-merge July 30, 2026 12:23
@github-actions github-actions Bot added 5.x ⚡ performance Performance degradation or optimization opportunity labels Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 02462b8a-e1ce-4a8f-9c6e-f5dd213064ea

📥 Commits

Reviewing files that changed from the base of the PR and between 1d818d5 and cd3271f.

📒 Files selected for processing (5)
  • packages/kit/src/module/define.ts
  • packages/kit/src/module/install.ts
  • packages/nuxt/src/app/plugins/dev-server-logs.ts
  • packages/nuxt/src/core/schema.ts
  • packages/nuxt/src/pages/module.ts

Walkthrough

Selected Kit and Nuxt dependencies are changed from static to dynamic imports. Jiti creation is cached per Nuxt instance, schema loading is initialised lazily, and typed-router utilities load during type preparation. The development-log plugin lazily loads Consola and Devalue and only emits parsed SSR logs when log content is present.

Possibly related PRs

  • nuxt/nuxt#35497: Both modify loadNuxtModuleInstance import and evaluation flow in packages/kit/src/module/install.ts.
  • nuxt/nuxt#35565: Both touch the typed-pages and typed-router DTS generation path in packages/nuxt/src/pages/module.ts.
  • nuxt/nuxt#35898: Both modify linkToAlias(...)-based diagnostic formatting in the schema and pages modules.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarises the main change: switching kit and nuxt imports to lazy loading for performance.
Description check ✅ Passed The description is directly related to the changeset and explains the parsing cost of the lazy-loaded imports.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/lazy-imports

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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/kit/src/module/install.ts`:
- Around line 287-298: Cache in-flight lazy-loader promises to prevent duplicate
initialization during concurrent calls. In packages/kit/src/module/install.ts
lines 287-298, change _jitiCache to store Promise<Jiti>, create and store the
promise immediately after a cache miss, then await and return it. In
packages/nuxt/src/core/schema.ts lines 21-37, make _resolveSchema promise-backed
and share the pending initialization using the same pattern.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f0a298c1-3e5f-432e-9d6f-ed384181c28b

📥 Commits

Reviewing files that changed from the base of the PR and between 4e12e32 and 1d818d5.

📒 Files selected for processing (5)
  • packages/kit/src/module/define.ts
  • packages/kit/src/module/install.ts
  • packages/nuxt/src/app/plugins/dev-server-logs.ts
  • packages/nuxt/src/core/schema.ts
  • packages/nuxt/src/pages/module.ts

Comment thread packages/kit/src/module/install.ts Resolved
@pkg-pr-new

pkg-pr-new Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@35901

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@35901

nuxt

npm i https://pkg.pr.new/nuxt@35901

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@35901

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@35901

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@35901

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@35901

commit: cd3271f

@codspeed

codspeed Bot commented Jul 30, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 21 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing perf/lazy-imports (cd3271f) with main (3d12b78)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@danielroe
danielroe force-pushed the perf/lazy-imports branch from 1d818d5 to cd3271f Compare July 30, 2026 13:09
@danielroe
danielroe added this pull request to the merge queue Jul 30, 2026
Merged via the queue into main with commit 7c38104 Jul 30, 2026
33 checks passed
@danielroe
danielroe deleted the perf/lazy-imports branch July 30, 2026 13:49
@github-actions github-actions Bot mentioned this pull request Jul 30, 2026
2 of 5 tasks
@github-actions github-actions Bot mentioned this pull request Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.x ⚡ performance Performance degradation or optimization opportunity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant