Skip to content

Commit c55840b

Browse files
committed
revert
1 parent c5b1439 commit c55840b

File tree

4 files changed

+97
-78
lines changed

4 files changed

+97
-78
lines changed

crates/rspack_core/src/cache/persistent/occasion/make/mod.rs

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ impl MakeOccasion {
6161
pub async fn recovery(&self) -> Result<MakeArtifact> {
6262
let (partial, module_to_lazy_make, entry_dependencies) =
6363
module_graph::recovery_module_graph(&self.storage, &self.context).await?;
64+
6465
// regenerate statistical data
6566
let mg = ModuleGraph::new([Some(&partial), None], None);
6667
// recovery make_failed_module
@@ -70,60 +71,22 @@ impl MakeOccasion {
7071
let mut context_dep = FileCounter::default();
7172
let mut missing_dep = FileCounter::default();
7273
let mut build_dep = FileCounter::default();
74+
for (mid, module) in mg.modules() {
75+
let build_info = module.build_info();
76+
file_dep.add_batch_file(&build_info.file_dependencies);
77+
context_dep.add_batch_file(&build_info.context_dependencies);
78+
missing_dep.add_batch_file(&build_info.missing_dependencies);
79+
build_dep.add_batch_file(&build_info.build_dependencies);
80+
if !module.diagnostics().is_empty() {
81+
make_failed_module.insert(mid);
82+
}
83+
}
7384

74-
let modules = mg.modules();
75-
rayon::scope(|s| {
76-
s.spawn(|_| {
77-
for module in modules.values() {
78-
let build_info = module.build_info();
79-
file_dep.add_batch_file(&build_info.file_dependencies);
80-
}
81-
});
82-
s.spawn(|_| {
83-
for module in modules.values() {
84-
let build_info = module.build_info();
85-
context_dep.add_batch_file(&build_info.context_dependencies);
86-
}
87-
});
88-
s.spawn(|_| {
89-
for module in modules.values() {
90-
let build_info = module.build_info();
91-
missing_dep.add_batch_file(&build_info.missing_dependencies);
92-
}
93-
});
94-
s.spawn(|_| {
95-
for module in modules.values() {
96-
let build_info = module.build_info();
97-
build_dep.add_batch_file(&build_info.build_dependencies);
98-
}
99-
});
100-
s.spawn(|_| {
101-
for (identifier, module) in &modules {
102-
if !module.diagnostics().is_empty() {
103-
make_failed_module.insert(*identifier);
104-
}
105-
}
106-
});
107-
});
108-
109-
let dependency_factorize_infos = mg.dependency_factorize_infos();
110-
rayon::scope(|s| {
111-
s.spawn(|_| {
112-
for factorize_info in dependency_factorize_infos.values() {
113-
file_dep.add_batch_file(&factorize_info.file_dependencies());
114-
}
115-
});
116-
s.spawn(|_| {
117-
for factorize_info in dependency_factorize_infos.values() {
118-
context_dep.add_batch_file(&factorize_info.context_dependencies());
119-
}
120-
});
121-
s.spawn(|_| {
122-
for factorize_info in dependency_factorize_infos.values() {
123-
missing_dep.add_batch_file(&factorize_info.missing_dependencies());
124-
}
125-
});
126-
});
85+
for (_, factorize_info) in mg.dependency_factorize_info_iter() {
86+
file_dep.add_batch_file(&factorize_info.file_dependencies());
87+
context_dep.add_batch_file(&factorize_info.context_dependencies());
88+
missing_dep.add_batch_file(&factorize_info.missing_dependencies());
89+
}
12790

12891
Ok(MakeArtifact {
12992
// write all of field here to avoid forget to update occasion when add new fields

crates/rspack_core/src/compilation/make/artifact.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ impl MakeArtifact {
186186
.collect::<Vec<_>>()
187187
});
188188
let make_failed_dependencies = mg
189-
.dependency_factorize_infos()
190-
.into_iter()
189+
.dependency_factorize_info_iter()
191190
.filter(|(_, info)| !info.is_success());
192191
let dep_diagnostics = make_failed_dependencies.flat_map(|(dep_id, factorize_info)| {
193192
let origin_module_identifier = mg.get_parent_module(&dep_id);

crates/rspack_core/src/compilation/make/graph_updater/cutout/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ impl Cutout {
7676
);
7777
force_build_deps.extend(
7878
module_graph
79-
.dependency_factorize_infos()
80-
.into_iter()
79+
.dependency_factorize_info_iter()
8180
// The cost of `factorize_info.depends_on` can be highly non-uniform.
8281
// To enable Rayon's work-stealing for better load balancing, we first
8382
// materialize the iterator into a Vec. This allows `par_iter` to create

crates/rspack_core/src/module_graph/mod.rs

Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -647,27 +647,8 @@ impl<'a> ModuleGraph<'a> {
647647
}
648648

649649
#[inline]
650-
pub fn dependency_factorize_infos(&self) -> HashMap<DependencyId, &FactorizeInfo> {
651-
let mut res = HashMap::default();
652-
for item in self.partials.iter().flatten() {
653-
for (k, v) in &item.dependency_factorize_infos {
654-
if let Some(v) = v {
655-
res.insert(*k, v);
656-
} else {
657-
res.remove(k);
658-
}
659-
}
660-
}
661-
if let Some(active) = &self.active {
662-
for (k, v) in &active.dependency_factorize_infos {
663-
if let Some(v) = v {
664-
res.insert(*k, v);
665-
} else {
666-
res.remove(k);
667-
}
668-
}
669-
}
670-
res
650+
pub fn dependency_factorize_info_iter(&'a self) -> FactorizeInfos<'a> {
651+
FactorizeInfos::new(self)
671652
}
672653

673654
pub fn add_dependency(&mut self, dependency: BoxDependency) {
@@ -1276,3 +1257,80 @@ impl<'a> ModuleGraph<'a> {
12761257
}
12771258
}
12781259
}
1260+
1261+
#[allow(clippy::type_complexity)]
1262+
pub enum FactorizeInfos<'a> {
1263+
// An optimized iterator for when there's only a single, read-only layer of data.
1264+
// It directly iterates over the underlying `HashMap` without any merging overhead,
1265+
// filtering out deleted entries (`None` values).
1266+
Direct(
1267+
std::iter::FilterMap<
1268+
std::collections::hash_map::Iter<'a, DependencyId, Option<FactorizeInfo>>,
1269+
fn((&DependencyId, &'a Option<FactorizeInfo>)) -> Option<(DependencyId, &'a FactorizeInfo)>,
1270+
>,
1271+
),
1272+
// An iterator for when multiple data layers exist (e.g., during the seal phase).
1273+
// It merges all layers into a temporary `HashMap` to correctly resolve overrides
1274+
// and deletions, then iterates over the merged result.
1275+
Merged(std::collections::hash_map::IntoIter<DependencyId, &'a FactorizeInfo>),
1276+
}
1277+
1278+
impl<'a> FactorizeInfos<'a> {
1279+
pub fn new(module_graph: &'a ModuleGraph<'a>) -> Self {
1280+
if module_graph.partials.iter().flatten().count() == 1 && module_graph.active.is_none() {
1281+
#[allow(clippy::unwrap_used)]
1282+
let partial = module_graph
1283+
.partials
1284+
.iter()
1285+
.find_map(|p| p.as_ref())
1286+
.unwrap();
1287+
Self::Direct(
1288+
partial
1289+
.dependency_factorize_infos
1290+
.iter()
1291+
.filter_map(|item| item.1.as_ref().map(|info| (*item.0, info))),
1292+
)
1293+
} else {
1294+
let mut merged = HashMap::default();
1295+
for item in module_graph.partials.iter().flatten() {
1296+
for (dependency_id, factorize_info) in &item.dependency_factorize_infos {
1297+
if let Some(factorize_info) = factorize_info {
1298+
merged.insert(*dependency_id, factorize_info);
1299+
} else {
1300+
merged.remove(dependency_id);
1301+
}
1302+
}
1303+
}
1304+
if let Some(active) = &module_graph.active {
1305+
for (dependency_id, factorize_info) in &active.dependency_factorize_infos {
1306+
if let Some(factorize_info) = factorize_info {
1307+
merged.insert(*dependency_id, factorize_info);
1308+
} else {
1309+
merged.remove(dependency_id);
1310+
}
1311+
}
1312+
}
1313+
Self::Merged(merged.into_iter())
1314+
}
1315+
}
1316+
}
1317+
1318+
impl<'a> Iterator for FactorizeInfos<'a> {
1319+
type Item = (DependencyId, &'a FactorizeInfo);
1320+
1321+
#[inline]
1322+
fn next(&mut self) -> Option<Self::Item> {
1323+
match self {
1324+
Self::Direct(iter) => iter.next(),
1325+
Self::Merged(iter) => iter.next(),
1326+
}
1327+
}
1328+
1329+
#[inline]
1330+
fn size_hint(&self) -> (usize, Option<usize>) {
1331+
match self {
1332+
Self::Direct(iter) => iter.size_hint(),
1333+
Self::Merged(iter) => iter.size_hint(),
1334+
}
1335+
}
1336+
}

0 commit comments

Comments
 (0)