Repository navigation
perf(build): normalize alias maps once before resolving - #4997
Merged
Merged
Conversation
`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]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
pi0
approved these changes
Nov 1, 2026
commit: |
Contributor
|
Caution Review failedThe pull request is closed.
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. |
This branch was successfully deployed
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.
Resolves #4988
resolveAliasfrompathe/utilssorts 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 normalizesbundlerConfig.base.aliasesonce and normalizes again only if the config object changes. The plugin moved tosrc/build/vite/_server-aliases.tsso it can be unit tested.resolveEnvPaths(all builders): calledresolveAliaswith the raw map for every alias, polyfill and inject entry. It now normalizes the map once before the loop.Verification
resolveBuildEnvoutput before and after for 10 presets (node-server, cloudflare-module/pages, netlify-edge, vercel, deno-server, bun, aws-lambda, azure-swa), each with defaultnodeand withnode: false. The output is byte-identical. Total time went from ~1008 ms to ~41 ms.test/unit/vite-server-aliases.test.tsand a case intest/unit/build-env.test.ts) fail without the fix.test/unit,test/viteand 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