Turbopack: make available_modules an OperationVc and simplify merged module bookkeeping#94055
Merged
Conversation
Splits ChunkGroupContent into ChunkGroupContentInner (a turbo_tasks value containing chunkable_items, batch_groups, async_modules, traced_modules, and available_modules) and a thin ChunkGroupContent wrapper that pairs it with the resulting AvailabilityInfo. chunk_group_content_operation runs inside turbo_tasks so its available_modules can be exposed as an OperationVc<AvailableModulesSet>, which AvailableModules now stores and .connect()s on read.
Replaces the separate `included` set and `should_create_chunk_item_for` method with an `Option<ChunkableModule>` value type on the `replacements` map: present-with-`Some` means "replace", present-with-`None` means "skip (already included in another merged module)", and absent means "keep as-is". Call sites now decide all three cases in one match on `should_replace_module`.
Contributor
Tests PassedCommit: 7ae6320 |
mischnic
approved these changes
May 26, 2026
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.
What?
Reworks how
chunk_group_contentexposesavailable_modulesfor downstream chunking, and consolidates the bookkeeping for merged modules inChunkGroup.ChunkGroupContentinto aturbo_tasks::valueChunkGroupContentInner(carryingchunkable_items,batch_groups,async_modules,traced_modules, andavailable_modules) plus a thin wrapper that pairs it with the resultingAvailabilityInfo.chunk_group_content_operationnow runs entirely insideturbo_tasks, allowingAvailableModulesto store its set as anOperationVc<AvailableModulesSet>and.connect()it on read.includedset andshould_create_chunk_item_formethod onMergedModuleInfowith anOption<ChunkableModule>value type on thereplacementsmap. Call sites now decide all three cases (replace / skip / keep) in one match viashould_replace_module.Why?
AvailableModules::snapshotdid not correctly derive its invalidation priority, which caused double invalidations: the snapshot was treated as a low-priority dependency even though it gated chunking work, so when its inputs changed turbo-tasks would invalidate it after dependent computations had already started, triggering them a second time. Exposingavailable_modulesas anOperationVcmakesAvailableModulesinherit the correct invalidation priority from the operation that produces it, which removes the double-invalidation.MergedModuleInfoAPI had two parallel data structures (replacementsandincluded) and a helper that combined them. Foldingincludedinto the value ofreplacementsremoves the duplication, makes the three states (replace, skip-because-merged, keep) explicit, and shrinks the call-site logic inchunk_group.rs.How?
available_modulesas anOperationVc:ChunkGroupContentInneris aturbo_tasks::valueholding the chunkable items, batch groups, async/traced modules, and anOperationVc<AvailableModulesSet>foravailable_modules.ChunkGroupContentbecomes a plain struct wrappingResolvedVc<ChunkGroupContentInner>together with theAvailabilityInfocomputed for the group.chunk_group_content_operationis anOperationVc-producing function so its inneravailable_modulescan be returned as anOperationVc<AvailableModulesSet>.AvailableModulesnow stores that operation Vc and.connect()s it whenever the set is read, so consumers reach the set through the operation and inherit its priority.make_chunk_groupand friends.MergedModuleInfosimplification:replacementschanges fromHashMap<ChunkableModule, ChunkableModule>toHashMap<ChunkableModule, Option<ChunkableModule>>:Some(m)means "replace withm",Nonemeans "skip — already included in another merged module", absent means "keep as-is".includedset andshould_create_chunk_item_forhelper are removed;should_replace_modulereturns the three-way outcome and consumers match on it once.chunk_group.rsare restructured around the single match so the logic is no longer split across two lookups.Notes
turbopack-core(chunk_group_content,available_modules,chunk_group) and the browser/nodejs chunking contexts.turbopack-coreexercise the new shape.