Skip to content

perf(build): normalize alias maps once before resolving - #4997

Merged
pi0 merged 1 commit into
mainfrom
perf/dedup-alias-resolve
Nov 1, 2026
Merged

pi0 merged 1 commit into
mainfrom
perf/dedup-alias-resolve

Conversation

@pi0x

@pi0x pi0x commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Resolves #4988

resolveAlias from pathe/utils sorts and expands the whole alias map on every call when it gets a plain object (cost grows with the square of the alias count). Two hot spots did this:

  • nitro:server-aliases (vite): has no hook filter, so it runs for every server module id. It now normalizes bundlerConfig.base.aliases once and normalizes again only if the config object changes. The plugin moved to src/build/vite/_server-aliases.ts so it can be unit tested.
  • resolveEnvPaths (all builders): called resolveAlias with the raw map for every alias, polyfill and inject entry. It now normalizes the map once before the loop.

Verification

  • I compared resolveBuildEnv output before and after for 10 presets (node-server, cloudflare-module/pages, netlify-edge, vercel, deno-server, bun, aws-lambda, azure-swa), each with default node and with node: false. The output is byte-identical. Total time went from ~1008 ms to ~41 ms.
  • New unit tests (test/unit/vite-server-aliases.test.ts and a case in test/unit/build-env.test.ts) fail without the fix.
  • test/unit, test/vite and the node and cloudflare-module preset tests (rolldown) pass.

The approach follows @onmax's branch from the issue (credited as co-author).

🤖 Generated with AI assistant

`resolveAlias` from `pathe/utils` normalizes a plain alias map on each
call. `nitro:server-aliases` (vite) and `resolveEnvPaths` now normalize
the map once and reuse it.

Co-authored-by: Max <[email protected]>
@pi0x
pi0x requested a review from pi0 as a code owner November 1, 2026 16:01
@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nitro.build Ready Ready Preview Nov 1, 2026 4:01pm UTC

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Nov 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4997

commit: d3edbb6

@coderabbitai

coderabbitai Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@pi0
pi0 merged commit 089fa53 into main Nov 1, 2026
16 of 17 checks passed
@pi0
pi0 deleted the perf/dedup-alias-resolve branch November 1, 2026 16:04

This branch was successfully deployed

1 active deployment
Preview — d3edbb65 Deployed Nov 1, 2026 by vercel[bot]
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.

Vite builder: nitro:server-aliases normalizes the full alias map for each module

2 participants