Skip to content

Commit 21e98e3

Browse files
committed
FxHasher in compute_chunk_group_info
1 parent 3ae8fb2 commit 21e98e3

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

turbopack/crates/turbopack-core/src/module_graph/chunk_group_info.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
use std::{
22
collections::{hash_map::Entry, BinaryHeap, HashMap, HashSet},
3-
hash::Hash,
3+
hash::{BuildHasherDefault, Hash},
44
ops::{Deref, DerefMut},
55
};
66

77
use anyhow::Result;
88
use either::Either;
99
use petgraph::graph::{DiGraph, EdgeIndex, NodeIndex};
1010
use roaring::RoaringBitmap;
11+
use rustc_hash::FxHasher;
1112
use serde::{Deserialize, Serialize};
1213
use tracing::Instrument;
1314
use turbo_rcstr::RcStr;
@@ -75,8 +76,10 @@ impl Hash for RoaringBitmapWrapper {
7576
}
7677
}
7778

79+
type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
80+
7881
#[turbo_tasks::value(transparent)]
79-
pub struct ChunkGroupInfo(HashMap<ResolvedVc<Box<dyn Module>>, RoaringBitmapWrapper>);
82+
pub struct ChunkGroupInfo(FxHashMap<ResolvedVc<Box<dyn Module>>, RoaringBitmapWrapper>);
8083

8184
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
8285
enum ChunkGroup {
@@ -164,18 +167,21 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
164167
let span = span_outer.clone();
165168
async move {
166169
let mut next_chunk_group_id = 0u32;
167-
let mut chunk_groups_to_id: HashMap<ChunkGroup, ChunkGroupId> = HashMap::new();
168-
let mut chunk_groups_from_id: HashMap<ChunkGroupId, ChunkGroup> = HashMap::new();
170+
let mut chunk_groups_to_id: FxHashMap<ChunkGroup, ChunkGroupId> =
171+
HashMap::with_hasher(BuildHasherDefault::<FxHasher>::default());
172+
let mut chunk_groups_from_id: FxHashMap<ChunkGroupId, ChunkGroup> =
173+
HashMap::with_hasher(BuildHasherDefault::<FxHasher>::default());
169174

170-
let mut module_chunk_groups: HashMap<ResolvedVc<Box<dyn Module>>, RoaringBitmapWrapper> =
171-
HashMap::new();
175+
let mut module_chunk_groups: FxHashMap<ResolvedVc<Box<dyn Module>>, RoaringBitmapWrapper> =
176+
HashMap::with_hasher(BuildHasherDefault::<FxHasher>::default());
172177

173178
let graphs = graph.graphs.iter().try_join().await?;
174179
let module_count = graphs.iter().map(|g| g.graph.node_count()).sum::<usize>();
175180
span.record("module_count", module_count);
176181

177182
// First, compute the depth for each module in the graph
178-
let mut module_depth: HashMap<ResolvedVc<Box<dyn Module>>, usize> = HashMap::new();
183+
let mut module_depth: FxHashMap<ResolvedVc<Box<dyn Module>>, usize> =
184+
HashMap::with_hasher(BuildHasherDefault::<FxHasher>::default());
179185
// use all entries from all graphs
180186
let entries = graphs
181187
.iter()
@@ -202,7 +208,7 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
202208
let mut visitor =
203209
|parent_info: Option<(&'_ SingleModuleGraphModuleNode, &'_ ChunkingType)>,
204210
node: &'_ SingleModuleGraphModuleNode,
205-
module_chunk_groups: &mut HashMap<
211+
module_chunk_groups: &mut FxHashMap<
206212
ResolvedVc<Box<dyn Module>>,
207213
RoaringBitmapWrapper,
208214
>|
@@ -316,7 +322,7 @@ pub async fn compute_chunk_group_info(graph: &ModuleGraph) -> Result<Vc<ChunkGro
316322
let mut visit_count = 0usize;
317323

318324
{
319-
let mut queue_set = HashSet::new();
325+
let mut queue_set = HashSet::with_hasher(BuildHasherDefault::<FxHasher>::default());
320326
let mut queue = BinaryHeap::with_capacity(entries.len());
321327
for e in entries {
322328
queue.push(NodeWithPriority {

0 commit comments

Comments
 (0)