Skip to content

Commit dc7556e

Browse files
committed
perf: improve exports info
1 parent bb519b6 commit dc7556e

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

crates/rspack_core/src/exports/exports_info_getter.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::sync::Arc;
22

33
use either::Either;
44
use itertools::Itertools;
5+
use rspack_collections::UkeyMap;
56
use rspack_util::{atom::Atom, ext::DynHash};
6-
use rustc_hash::FxHashMap as HashMap;
77

88
use super::{
99
ExportInfoData, ExportProvided, ExportsInfo, ProvidedExports, UsageState, UsedName, UsedNameItem,
@@ -31,7 +31,7 @@ pub struct PrefetchedExportsInfoWrapper<'a> {
3131
* stored in a map to prevent circular references
3232
* When redirect, this data can be cloned to generate a new PrefetchedExportsInfoWrapper with a new entry
3333
*/
34-
exports: Arc<HashMap<ExportsInfo, &'a ExportsInfoData>>,
34+
exports: Arc<UkeyMap<ExportsInfo, &'a ExportsInfoData>>,
3535
/**
3636
* The entry of the current exports info
3737
*/
@@ -569,7 +569,7 @@ impl ExportsInfoGetter {
569569
fn prefetch_exports<'a>(
570570
id: &ExportsInfo,
571571
mg: &'a ModuleGraph,
572-
res: &mut HashMap<ExportsInfo, &'a ExportsInfoData>,
572+
res: &mut UkeyMap<ExportsInfo, &'a ExportsInfoData>,
573573
mode: PrefetchExportsInfoMode<'a>,
574574
) {
575575
if res.contains_key(id) {
@@ -581,15 +581,12 @@ impl ExportsInfoGetter {
581581
match mode {
582582
PrefetchExportsInfoMode::Default => {}
583583
PrefetchExportsInfoMode::Nested(names) => {
584-
for (key, export_info) in exports_info.exports().iter() {
585-
if names.first().is_some_and(|name| name == key)
586-
&& let Some(nested_exports_info) = export_info.exports_info()
587-
{
588-
nested_exports.push((
589-
nested_exports_info,
590-
PrefetchExportsInfoMode::Nested(&names[1..]),
591-
));
592-
}
584+
if let Some(nested) = names
585+
.first()
586+
.and_then(|name| exports_info.exports().get(name))
587+
.and_then(|export_info| export_info.exports_info())
588+
{
589+
nested_exports.push((nested, PrefetchExportsInfoMode::Nested(&names[1..])));
593590
}
594591
}
595592
PrefetchExportsInfoMode::Full => {
@@ -620,7 +617,7 @@ impl ExportsInfoGetter {
620617
}
621618
}
622619

623-
let mut res = HashMap::default();
620+
let mut res = UkeyMap::default();
624621
prefetch_exports(id, mg, &mut res, mode.clone());
625622
PrefetchedExportsInfoWrapper {
626623
exports: Arc::new(res),
@@ -748,7 +745,7 @@ impl ExportsInfoGetter {
748745
let exports = exports
749746
.into_iter()
750747
.map(|e| (e, mg.get_exports_info_by_id(&e)))
751-
.collect::<HashMap<_, _>>();
748+
.collect::<UkeyMap<_, _>>();
752749

753750
PrefetchedExportsInfoWrapper {
754751
exports: Arc::new(exports),

0 commit comments

Comments
 (0)