Skip to content

fix(dev): prune dynamic import entry points when their imports are removed#10117

Draft
shulaoda wants to merge 1 commit into
mainfrom
07-03-fix_dev_prune_dynamic_import_entry_points_when_their_imports_are_removed
Draft

fix(dev): prune dynamic import entry points when their imports are removed#10117
shulaoda wants to merge 1 commit into
mainfrom
07-03-fix_dev_prune_dynamic_import_entry_points_when_their_imports_are_removed

Conversation

@shulaoda

@shulaoda shulaoda commented Jul 3, 2026

Copy link
Copy Markdown
Member

Description

Part of #7416. Stacked on #10115. This makes ScanStageCache::merge clean up dynamic import entry points when the dynamic imports behind them go away. Until now the entry list only ever grew.

Problem

Two related gaps in the entry point handling of merge:

  1. Stale related_stmt_infos rows. The old code removed a re-scanned importer's rows only when the scan output contained a matching entry point, keyed by the incoming rows. When a re-scanned module removed its dynamic import entirely, the scan output had no entry for the target at all, so the importer's old rows stayed behind and kept pointing at statement and node ids of a module version that no longer exists.
  2. Zombie entries. When the last dynamic importer of a module disappeared, the DynamicImport entry point stayed in the cache forever. Every incremental rebuild kept emitting a chunk for a module nothing imports dynamically anymore, which a fresh full build of the same files would not produce.

Fix

  • Before merging the incoming entry points, drop the rows of every re-scanned module from the cached dynamic import entries. The incoming entries then re-add exactly the rows that still exist. This subsumes the old incoming-keyed extract_if, which is removed.
  • After merging, prune every DynamicImport entry whose module no longer has any dynamic edge in the importers edge list. The edge list is reliable at merge time since fix(dev): update importer relationships of cached modules in incremental build #10107 and fix(dev): revert cache mutations when a partial scan fails #10110. Other entry kinds are untouched.
  • The prune is intentionally not transitive on the cache: edges of orphaned importers survive in the edge list, so an entry only they point at stays cached, and re-adding an import of the orphan revives the entry without a re-scan. ScanStageCache::create_output compensates by filtering DynamicImport entries against module reachability (compute_live_modules, a BFS from the non dynamic entries), so only entries a live module dynamically imports produce chunks, matching a fresh build. This covers the transitive case: main imports hub, hub dynamically imports lazy, and dropping the hub import from main must also stop emitting the lazy chunk even though hub is never re-scanned.
  • Partial scans no longer create a DynamicImport entry for a module that is a configured user entry. The scan local user_defined_entry_ids set is empty in partial mode, so the existing full scan filter never matched there, and a dynamic import of the entry module produced a second entry row (and a second chunk) for it.

Tests

  • New fixture hmr/remove_transitive_dynamic_import_entry: main statically imports hub, hub dynamically imports lazy. Dropping the hub import from main removes the lazy chunk from the build output without re-scanning hub; re-adding it revives the chunk.
  • New fixture hmr/remove_dynamic_import_entry: two modules dynamically import lazy.js and drop it one by one. After the first drop the entry survives through the remaining importer. After the second drop the lazy.js chunk disappears from the build output. Re-adding the import brings the entry and the chunk back.
  • The state parity check from test(dev): assert incremental scan state matches a fresh full build after each HMR step #10115 is tightened for this: DynamicImport entries now must match a fresh full build exactly while a live module imports them; an entry kept in the cache only by orphans' dynamic import records is tolerated, since create_output filters it from the output and it exists precisely to make revival cheap (other kinds still allow extras on the incremental side until orphan cleanup lands). Reintroducing the bug locally makes the parity check fail on the new fixture with "dynamic import entry only exists in the incremental state", so the whole HMR suite now guards this behavior.

Docs

The entry point step of the merge algorithm in internal-docs/cache/implementation.md is updated.

shulaoda commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label graphite: merge-when-ready to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq

codspeed-hq Bot commented Jul 3, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing 07-03-fix_dev_prune_dynamic_import_entry_points_when_their_imports_are_removed (507523a) with 07-03-test_dev_assert_incremental_scan_state_matches_a_fresh_full_build_after_each_hmr_step (0928e71)

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@shulaoda
shulaoda marked this pull request as draft July 3, 2026 11:43
@shulaoda
shulaoda changed the base branch from 07-03-test_dev_assert_incremental_scan_state_matches_a_fresh_full_build_after_each_hmr_step to graphite-base/10117 July 3, 2026 12:06
@shulaoda
shulaoda force-pushed the graphite-base/10117 branch from 0928e71 to d7c462d Compare July 3, 2026 12:21
@shulaoda
shulaoda force-pushed the 07-03-fix_dev_prune_dynamic_import_entry_points_when_their_imports_are_removed branch from 507523a to 9633216 Compare July 3, 2026 12:21
@shulaoda
shulaoda changed the base branch from graphite-base/10117 to 07-03-test_dev_assert_incremental_scan_state_matches_a_fresh_full_build_after_each_hmr_step July 3, 2026 12:21
@shulaoda
shulaoda force-pushed the 07-03-test_dev_assert_incremental_scan_state_matches_a_fresh_full_build_after_each_hmr_step branch from d7c462d to 818e66b Compare July 3, 2026 12:44
@shulaoda
shulaoda force-pushed the 07-03-fix_dev_prune_dynamic_import_entry_points_when_their_imports_are_removed branch from 9633216 to 11d0c68 Compare July 3, 2026 12:44
@graphite-app
graphite-app Bot force-pushed the 07-03-test_dev_assert_incremental_scan_state_matches_a_fresh_full_build_after_each_hmr_step branch from 818e66b to b4374de Compare July 6, 2026 07:26
@graphite-app
graphite-app Bot force-pushed the 07-03-fix_dev_prune_dynamic_import_entry_points_when_their_imports_are_removed branch from 11d0c68 to 3f003ea Compare July 6, 2026 07:27
@shulaoda
shulaoda force-pushed the 07-03-test_dev_assert_incremental_scan_state_matches_a_fresh_full_build_after_each_hmr_step branch from b4374de to b7d9a8e Compare July 6, 2026 08:34
@shulaoda
shulaoda force-pushed the 07-03-fix_dev_prune_dynamic_import_entry_points_when_their_imports_are_removed branch from 3f003ea to f8475df Compare July 6, 2026 08:34
@graphite-app
graphite-app Bot changed the base branch from 07-03-test_dev_assert_incremental_scan_state_matches_a_fresh_full_build_after_each_hmr_step to graphite-base/10117 July 6, 2026 08:43
@graphite-app
graphite-app Bot force-pushed the graphite-base/10117 branch from b7d9a8e to aabb746 Compare July 6, 2026 08:48
@graphite-app
graphite-app Bot force-pushed the 07-03-fix_dev_prune_dynamic_import_entry_points_when_their_imports_are_removed branch from f8475df to 4338591 Compare July 6, 2026 08:48
@graphite-app
graphite-app Bot changed the base branch from graphite-base/10117 to main July 6, 2026 08:49
@graphite-app
graphite-app Bot force-pushed the 07-03-fix_dev_prune_dynamic_import_entry_points_when_their_imports_are_removed branch from 4338591 to e5138d0 Compare July 6, 2026 08:49
@netlify

netlify Bot commented Jul 6, 2026

Copy link
Copy Markdown

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit e5138d0
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6a4b6c088502bb00080155fa

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