Skip to content

Commit

Permalink
fix: rebuild should reset module.preOrderIndex (#8413)
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng authored Dec 2, 2024
1 parent 5a967f7 commit ee8979a
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 4 deletions.
30 changes: 29 additions & 1 deletion crates/rspack_core/src/old_cache/local/code_splitting_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tracing::instrument;

use crate::{
build_chunk_graph::code_splitter::CodeSplitter, incremental::IncrementalPasses, ChunkByUkey,
ChunkGraph, ChunkGroupByUkey, ChunkGroupUkey, ChunkUkey, Compilation,
ChunkGraph, ChunkGroupByUkey, ChunkGroupUkey, ChunkUkey, Compilation, ModuleIdentifier,
};

#[derive(Debug, Default)]
Expand All @@ -19,6 +19,7 @@ pub struct CodeSplittingCache {
named_chunk_groups: HashMap<String, ChunkGroupUkey>,
named_chunks: HashMap<String, ChunkUkey>,
pub(crate) code_splitter: CodeSplitter,
pub(crate) module_idx: HashMap<ModuleIdentifier, (u32, u32)>,
}

#[instrument(skip_all)]
Expand Down Expand Up @@ -55,6 +56,17 @@ where
s.spawn(|_| compilation.named_chunks = cache.named_chunks.clone());
});

let module_idx = cache.module_idx.clone();
let mut module_graph = compilation.get_module_graph_mut();
for (m, (pre, post)) in module_idx {
let Some(mgm) = module_graph.module_graph_module_by_identifier_mut(&m) else {
continue;
};

mgm.pre_order_index = Some(pre);
mgm.post_order_index = Some(post);
}

if !has_change {
return Ok(());
}
Expand All @@ -71,5 +83,21 @@ where
s.spawn(|_| cache.named_chunk_groups = compilation.named_chunk_groups.clone());
s.spawn(|_| cache.named_chunks = compilation.named_chunks.clone());
});

let mg = compilation.get_module_graph();
let mut map = HashMap::default();
for m in mg.modules().keys() {
let Some(mgm) = mg.module_graph_module_by_identifier(m) else {
continue;
};

let (Some(pre), Some(post)) = (mgm.pre_order_index, mgm.post_order_index) else {
continue;
};

map.insert(*m, (pre, post));
}
let cache = &mut compilation.code_splitting_cache;
cache.module_idx = map;
Ok(())
}
4 changes: 1 addition & 3 deletions crates/rspack_ids/src/deterministic_module_ids_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ fn module_ids(&self, compilation: &mut Compilation) -> Result<()> {
|m| get_full_module_name(m, context),
|a, b| compare_modules_by_pre_order_index_or_identifier(&module_graph, a, b),
|module, id| {
let size = used_ids.len();
used_ids.insert(id.to_string());
if used_ids.len() == size {
if !used_ids.insert(id.to_string()) {
conflicts += 1;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import v from './lib'

it('should compile', async () => {
expect(v).toBe(1)
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// change
export default 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
optimization: {
splitChunks: false,
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
checkStats(_stepName, stats) {
// should keep module preOrderIndex and postOrderIndex during build
return [...stats.modules].filter(m => {
return m.moduleType !== 'runtime'
}).every((m) => {
return m.preOrderIndex !== undefined && m.postOrderIndex !== undefined
})
}
}

2 comments on commit ee8979a

@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-12-02 5a967f7) Current Change
10000_big_production-mode_disable-minimize + exec 42.8 s ± 1.97 s 42 s ± 473 ms -1.78 %
10000_development-mode + exec 1.8 s ± 45 ms 1.79 s ± 29 ms -0.58 %
10000_development-mode_hmr + exec 648 ms ± 5.5 ms 645 ms ± 4.5 ms -0.43 %
10000_production-mode + exec 2.39 s ± 30 ms 2.39 s ± 46 ms -0.28 %
arco-pro_development-mode + exec 1.73 s ± 82 ms 1.75 s ± 90 ms +1.15 %
arco-pro_development-mode_hmr + exec 426 ms ± 2.5 ms 426 ms ± 2.2 ms +0.13 %
arco-pro_production-mode + exec 3.13 s ± 60 ms 3.13 s ± 72 ms +0.16 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.16 s ± 77 ms 3.14 s ± 78 ms -0.45 %
threejs_development-mode_10x + exec 1.62 s ± 15 ms 1.63 s ± 20 ms +0.07 %
threejs_development-mode_10x_hmr + exec 810 ms ± 8.1 ms 809 ms ± 2.1 ms -0.14 %
threejs_production-mode_10x + exec 4.94 s ± 37 ms 4.91 s ± 52 ms -0.60 %
10000_big_production-mode_disable-minimize + rss memory 13399 MiB ± 459 MiB 13366 MiB ± 97.1 MiB -0.24 %
10000_development-mode + rss memory 775 MiB ± 13.2 MiB 794 MiB ± 87.6 MiB +2.45 %
10000_development-mode_hmr + rss memory 2010 MiB ± 398 MiB 1955 MiB ± 373 MiB -2.74 %
10000_production-mode + rss memory 671 MiB ± 27.6 MiB 664 MiB ± 32.3 MiB -0.96 %
arco-pro_development-mode + rss memory 741 MiB ± 47.6 MiB 722 MiB ± 37.2 MiB -2.47 %
arco-pro_development-mode_hmr + rss memory 922 MiB ± 152 MiB 959 MiB ± 114 MiB +4.00 %
arco-pro_production-mode + rss memory 878 MiB ± 26.9 MiB 881 MiB ± 26.9 MiB +0.33 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 871 MiB ± 38.5 MiB 858 MiB ± 64 MiB -1.53 %
threejs_development-mode_10x + rss memory 830 MiB ± 31.6 MiB 822 MiB ± 59.5 MiB -0.86 %
threejs_development-mode_10x_hmr + rss memory 2115 MiB ± 194 MiB 2172 MiB ± 128 MiB +2.70 %
threejs_production-mode_10x + rss memory 1037 MiB ± 68.4 MiB 1046 MiB ± 51.1 MiB +0.85 %

@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
rsdoctor ✅ success
rspress ✅ success
rslib ❌ failure
rsbuild ✅ success
examples ✅ success
devserver ✅ success
nuxt ✅ success

Please sign in to comment.