Skip to content

perf: skip i18n context setup for build asset requests - #4145

Open
lazerg wants to merge 1 commit into
nuxt-modules:mainfrom
lazerg:perf/skip-build-asset-requests
Open

perf: skip i18n context setup for build asset requests#4145
lazerg wants to merge 1 commit into
nuxt-modules:mainfrom
lazerg:perf/skip-build-asset-requests

Conversation

@lazerg

@lazerg lazerg commented Aug 23, 2026

Copy link
Copy Markdown

The nitro request hook sets up the i18n context for every request, including the /_nuxt/* chunks a node-server deployment serves itself. That setup calls useRuntimeConfig(event), which clones the whole runtime config and walks every key looking for env overrides, so a 442-byte JS chunk pays for a full config pass it never reads. The reporter profiled it at ~16.5% of non-idle CPU, with throughput dropping from ~9060 rps on Nuxt 3.15 + i18n 9.5.6 to ~2065 rps on 10.6.0.

The hook now returns early for paths under app.buildAssetsDir, resolved once during plugin setup. Nothing downstream reads the context on that path: nitro serves or 404s build assets before render:before runs, so useI18nContext is never reached for them. The reporter measured ~8290 rps with the same guard, and SSR requests are unaffected.

Summary by CodeRabbit

  • Bug Fixes

    • Prevented i18n initialization for build asset requests, improving asset delivery and avoiding unnecessary request processing.
    • Preserved i18n initialization for regular page requests, including applications served from the root path.
  • Tests

    • Added coverage for build assets with and without a configured base URL, as well as standard page requests.

@lazerg
lazerg requested a review from BobbieGoede as a code owner August 23, 2026 08:31
@lazerg
lazerg force-pushed the perf/skip-build-asset-requests branch from 7e081ed to d53377d Compare August 23, 2026 08:33
@coderabbitai

coderabbitai Bot commented Aug 23, 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: 9770ceda-0671-4246-b28a-677bc2906144

📥 Commits

Reviewing files that changed from the base of the PR and between d53377d and f863974.

📒 Files selected for processing (5)
  • src/runtime/server/plugin.ts
  • test/mocks/nuxt.internal-config.ts
  • test/server-plugin.test.ts
  • test/setup.ts
  • vitest.config.test.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review.


Walkthrough

The server plugin derives the build-assets path from runtime configuration and skips i18n context initialization for matching requests. New tests cover default and base URLs, page requests, and root asset paths. Test mocks, Vitest aliases, and a global stub support isolated server-plugin testing.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to f8639

This localized performance change avoids unnecessary i18n setup for build asset requests without identified functional impact; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: skipping i18n context setup for build asset requests.
Linked Issues check ✅ Passed The implementation and tests address issue #4144 by skipping i18n setup for build assets while preserving page request handling.
Out of Scope Changes check ✅ Passed The code, test, mock, and Vitest configuration changes directly support the performance fix described in issue #4144.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@lazerg
lazerg force-pushed the perf/skip-build-asset-requests branch from d53377d to f863974 Compare August 23, 2026 08:40
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.

initializeI18nContext runs on every request and response times at our ingress go from ~50 ms to 250–500 ms

1 participant