Unverified Commit e1c8cc72 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

Turbopack: Remove chunk group id from value of chunk groups map (#95142)

It looks like we were redundantly storing these group ids in the
`FxIndexMap`, when we could just use it's entry position.
parent e630d818
...@@ -455,10 +455,9 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro ...@@ -455,10 +455,9 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
let span = span_outer.clone(); let span = span_outer.clone();
async move { async move {
#[allow(clippy::type_complexity)]
let mut chunk_groups_map: FxIndexMap< let mut chunk_groups_map: FxIndexMap<
ChunkGroupKey, ChunkGroupKey,
(ChunkGroupId, FxIndexSet<ResolvedVc<Box<dyn Module>>>), FxIndexSet<ResolvedVc<Box<dyn Module>>>,
> = FxIndexMap::default(); > = FxIndexMap::default();
// For each module, the indices in the bitmap store which chunk groups in `chunk_groups_map` // For each module, the indices in the bitmap store which chunk groups in `chunk_groups_map`
...@@ -502,12 +501,11 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro ...@@ -502,12 +501,11 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
// ---- // ----
#[allow(clippy::type_complexity)]
fn entry_to_chunk_group_id( fn entry_to_chunk_group_id(
entry: ChunkGroupEntry, entry: ChunkGroupEntry,
chunk_groups_map: &mut FxIndexMap< chunk_groups_map: &mut FxIndexMap<
ChunkGroupKey, ChunkGroupKey,
(ChunkGroupId, FxIndexSet<ResolvedVc<Box<dyn Module>>>), FxIndexSet<ResolvedVc<Box<dyn Module>>>,
>, >,
) -> ChunkGroupKey { ) -> ChunkGroupKey {
match entry { match entry {
...@@ -522,14 +520,12 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro ...@@ -522,14 +520,12 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
entries: _, entries: _,
} => { } => {
let parent = entry_to_chunk_group_id(*parent, chunk_groups_map); let parent = entry_to_chunk_group_id(*parent, chunk_groups_map);
let len = chunk_groups_map.len(); let parent_entry = chunk_groups_map.entry(parent);
let parent = chunk_groups_map let parent_id = parent_entry.index();
.entry(parent) parent_entry.or_default();
.or_insert_with(|| (ChunkGroupId(len as u32), FxIndexSet::default()))
.0;
ChunkGroupKey::IsolatedMerged { ChunkGroupKey::IsolatedMerged {
parent: ChunkGroupId(*parent), parent: ChunkGroupId::from(parent_id),
merge_tag, merge_tag,
} }
} }
...@@ -539,14 +535,12 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro ...@@ -539,14 +535,12 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
entries: _, entries: _,
} => { } => {
let parent = entry_to_chunk_group_id(*parent, chunk_groups_map); let parent = entry_to_chunk_group_id(*parent, chunk_groups_map);
let len = chunk_groups_map.len(); let parent_entry = chunk_groups_map.entry(parent);
let parent = chunk_groups_map let parent_id = parent_entry.index();
.entry(parent) parent_entry.or_default();
.or_insert_with(|| (ChunkGroupId(len as u32), FxIndexSet::default()))
.0;
ChunkGroupKey::SharedMerged { ChunkGroupKey::SharedMerged {
parent: ChunkGroupId(*parent), parent: ChunkGroupId::from(parent_id),
merge_tag, merge_tag,
} }
} }
...@@ -660,7 +654,6 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro ...@@ -660,7 +654,6 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
ChunkGroupInheritance::ChunkGroup(chunk_groups) => { ChunkGroupInheritance::ChunkGroup(chunk_groups) => {
// Start of a new chunk group, don't inherit anything from parent // Start of a new chunk group, don't inherit anything from parent
let chunk_group_ids = chunk_groups.map(|chunk_group| { let chunk_group_ids = chunk_groups.map(|chunk_group| {
let len = chunk_groups_map.len();
// For merged groups, the parent group id whose heuristics they inherit. // For merged groups, the parent group id whose heuristics they inherit.
let merged_parent = match &chunk_group { let merged_parent = match &chunk_group {
ChunkGroupKey::IsolatedMerged { parent, .. } ChunkGroupKey::IsolatedMerged { parent, .. }
...@@ -669,20 +662,20 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro ...@@ -669,20 +662,20 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
}; };
let id = match chunk_groups_map.entry(chunk_group) { let id = match chunk_groups_map.entry(chunk_group) {
Entry::Occupied(mut e) => { Entry::Occupied(mut e) => {
let (id, merged_entries) = e.get_mut(); let id = e.index() as u32;
if merged_parent.is_some() { if merged_parent.is_some() {
merged_entries.insert(node); e.get_mut().insert(node);
} }
**id id
} }
Entry::Vacant(e) => { Entry::Vacant(e) => {
let chunk_group_id = len as u32; let id = e.index() as u32;
let mut set = FxIndexSet::default(); let mut set = FxIndexSet::default();
if merged_parent.is_some() { if merged_parent.is_some() {
set.insert(node); set.insert(node);
} }
e.insert((ChunkGroupId(chunk_group_id), set)); e.insert(set);
chunk_group_id id
} }
}; };
// Record heuristics-inheritance edges into this chunk group: merged // Record heuristics-inheritance edges into this chunk group: merged
...@@ -871,7 +864,7 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro ...@@ -871,7 +864,7 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
}, },
chunk_groups: chunk_groups_map chunk_groups: chunk_groups_map
.into_iter() .into_iter()
.map(|(k, (_, merged_entries))| match k { .map(|(k, merged_entries)| match k {
ChunkGroupKey::Entry(entries) => ChunkGroup::Entry(entries), ChunkGroupKey::Entry(entries) => ChunkGroup::Entry(entries),
ChunkGroupKey::Async(module) => ChunkGroup::Async(module), ChunkGroupKey::Async(module) => ChunkGroup::Async(module),
ChunkGroupKey::Isolated(module) => ChunkGroup::Isolated(module), ChunkGroupKey::Isolated(module) => ChunkGroup::Isolated(module),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment