perf(ssr): only record import-binding identifiers in ssrTransform#22720
Draft
shulaoda wants to merge 1 commit into
Draft
perf(ssr): only record import-binding identifiers in ssrTransform#22720shulaoda wants to merge 1 commit into
shulaoda wants to merge 1 commit into
Conversation
ce5fd35 to
7fd633f
Compare
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.
During the AST walk in
ssrTransform, every reference identifier was recorded with a full parent-stack snapshot, even though only import-binding identifiers are ever acted upon.Problem
walkpushed[node, parentStack.slice(0)]intoidentifiers, then the final BFS pass re-ranisInScopeand calledonIdentifier.onIdentifierimmediately returns for any name not inidToImportMap. Since most identifiers in a module are locals/globals, the vast majority of thoseparentStack.slice(0)allocations and secondisInScopescans are wasted.Fix
idToImportMapintowalkand gate the record withidToImportMap.has(node.name)as the first (cheapest) check. Non-import identifiers are no longer snapshotted or re-scanned.idToImportMapis fully populated before the walk and only read during it, so output is unchanged.Tests
ssrTransformsuite (71 tests) passes unchanged, confirming identical output.vitest bench: the worst-case path improved from ~27.5ms to ~6.5ms mean (~4.3×).