Skip to content

perf(ssr): only record import-binding identifiers in ssrTransform#22720

Draft
shulaoda wants to merge 1 commit into
mainfrom
shulaoda/06-19-perf_ssr_only_record_import_binding_identifiers_in_ssrtransform
Draft

perf(ssr): only record import-binding identifiers in ssrTransform#22720
shulaoda wants to merge 1 commit into
mainfrom
shulaoda/06-19-perf_ssr_only_record_import_binding_identifiers_in_ssrtransform

Conversation

@shulaoda

@shulaoda shulaoda commented Jun 19, 2026

Copy link
Copy Markdown
Member

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

  • For each reference identifier, walk pushed [node, parentStack.slice(0)] into identifiers, then the final BFS pass re-ran isInScope and called onIdentifier.
  • onIdentifier immediately returns for any name not in idToImportMap. Since most identifiers in a module are locals/globals, the vast majority of those parentStack.slice(0) allocations and second isInScope scans are wasted.

Fix

  • Pass idToImportMap into walk and gate the record with idToImportMap.has(node.name) as the first (cheapest) check. Non-import identifiers are no longer snapshotted or re-scanned. idToImportMap is fully populated before the walk and only read during it, so output is unchanged.

Tests

  • No new test is included: this is a behavior-preserving optimization with byte-identical output, so there is nothing new to assert. The existing ssrTransform suite (71 tests) passes unchanged, confirming identical output.
  • Measured with a microbenchmark (1 import + ~2000 local references) via vitest bench: the worst-case path improved from ~27.5ms to ~6.5ms mean (~4.3×).

@shulaoda shulaoda marked this pull request as draft June 19, 2026 12:31
@shulaoda shulaoda force-pushed the shulaoda/06-19-perf_ssr_only_record_import_binding_identifiers_in_ssrtransform branch from ce5fd35 to 7fd633f Compare June 19, 2026 12:42
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.

1 participant