Skip to content

perf(hmr): avoid eager subChain allocation in propagateUpdate#22719

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

perf(hmr): avoid eager subChain allocation in propagateUpdate#22719
shulaoda wants to merge 1 commit into
mainfrom
shulaoda/06-19-perf_hmr_avoid_eager_subchain_allocation_in_propagateupdate

Conversation

@shulaoda

@shulaoda shulaoda commented Jun 19, 2026

Copy link
Copy Markdown
Member

In propagateUpdate, subChain was allocated at the top of the importer loop for every importer, but it is only used in two branches.

Problem

  • const subChain = currentChain.concat(importer) runs for every importer edge during HMR propagation.
  • It is only consumed by the acceptedHmrDeps branch and the recursive call. The acceptedHmrExports branch continues without ever using it — so for modules accepted via export bindings (e.g. barrel/re-export files with many importers), each allocation is immediately discarded.

Fix

  • Inline currentChain.concat(importer) at the two sites that actually use it, so the export-accepting continue path allocates nothing. The two sites are mutually exclusive, so this computes the chain at most once per importer. No behavior change.

Tests

  • No test is included: this is a behavior-preserving change that only defers an allocation, so there is no observable behavior difference to assert (a fails-without/passes-with test isn't possible). propagateUpdate correctness remains covered by the existing HMR tests and the playground/hmr e2e suite.

@shulaoda shulaoda marked this pull request as draft June 19, 2026 12:28
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