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 Oct 17, 2024
1 parent fc0751c commit 040af59
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

2 comments on commit 040af59

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-10-17 1626c72) Current Change
10000_development-mode + exec 2.18 s ± 39 ms 2.13 s ± 21 ms -2.12 %
10000_development-mode_hmr + exec 670 ms ± 28 ms 667 ms ± 11 ms -0.37 %
10000_production-mode + exec 2.69 s ± 39 ms 2.69 s ± 27 ms -0.22 %
arco-pro_development-mode + exec 1.82 s ± 80 ms 1.8 s ± 71 ms -1.47 %
arco-pro_development-mode_hmr + exec 426 ms ± 1.4 ms 426 ms ± 0.41 ms -0.12 %
arco-pro_production-mode + exec 3.32 s ± 57 ms 3.15 s ± 76 ms -5.33 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.33 s ± 92 ms 3.24 s ± 61 ms -2.63 %
threejs_development-mode_10x + exec 1.6 s ± 16 ms 1.61 s ± 23 ms +0.16 %
threejs_development-mode_10x_hmr + exec 760 ms ± 21 ms 761 ms ± 7.5 ms +0.10 %
threejs_production-mode_10x + exec 4.97 s ± 24 ms 4.97 s ± 30 ms +0.02 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
rspress ✅ success
rslib ✅ success
rsbuild ✅ success
examples ✅ success
devserver ✅ success

Please sign in to comment.