Skip to content

Commit

Permalink
fix: perf degradation in devtool plugin (#8147)
Browse files Browse the repository at this point in the history
fix: perf degradation
  • Loading branch information
SyMind authored and easy1090 committed Oct 17, 2024
1 parent 87135f6 commit 8fb89c6
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions crates/rspack_plugin_devtool/src/source_map_dev_tool_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,24 @@ impl SourceMapDevToolPlugin {
let output_options = &compilation.options.output;
let map_options = MapOptions::new(self.columns);

let futures = raw_assets
let matches = if let Some(test) = &self.test {
let features = raw_assets.iter().map(|(file, _)| test(file.to_owned()));
join_all(features)
.await
.into_iter()
.collect::<Result<Vec<_>>>()?
} else {
vec![]
};

let mut mapped_sources = raw_assets
.into_par_iter()
.map(|(file, asset)| async {
let is_match = match &self.test {
Some(test) => match test(file.to_owned()).await {
Ok(val) => val,
Err(e) => return Some(Err(e)),
},
None => true,
.enumerate()
.filter_map(|(index, (file, asset))| {
let is_match = if matches.is_empty() {
true
} else {
matches[index]
};
let source = if is_match {
asset.get_source().map(|source| {
Expand All @@ -191,16 +200,10 @@ impl SourceMapDevToolPlugin {
} else {
None
};
source.map(Ok)
source
})
.collect::<Vec<_>>();

let mut mapped_sources = join_all(futures)
.await
.into_iter()
.flatten()
.collect::<Result<Vec<_>>>()?;

let source_map_modules = mapped_sources
.par_iter()
.filter_map(|(_file, _asset, source_map)| source_map.as_ref())
Expand Down

0 comments on commit 8fb89c6

Please sign in to comment.