Skip to content

Commit

Permalink
refactor: code splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
JSerFeng committed Jan 2, 2025
1 parent 46e8278 commit d4e7793
Show file tree
Hide file tree
Showing 15 changed files with 1,743 additions and 36 deletions.
13 changes: 8 additions & 5 deletions crates/rspack_core/src/build_chunk_graph/code_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
assign_depths(
&mut assign_depths_map,
&compilation.get_module_graph(),
modules.iter().collect(),
modules.iter(),
);
input_entrypoints_and_modules.insert(entry_point, modules);
}
Expand Down Expand Up @@ -1535,7 +1535,11 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
return modules.clone();
}

self.extract_block_modules(module.get_root_block(compilation), runtime, compilation);
self.extract_block_modules(
module.get_root_block(&compilation.get_module_graph()),
runtime,
compilation,
);
self
.block_modules_runtime_map
.get::<OptionalRuntimeSpec>(&runtime.cloned().into())
Expand Down Expand Up @@ -1928,11 +1932,10 @@ pub(crate) enum DependenciesBlockIdentifier {
}

impl DependenciesBlockIdentifier {
pub fn get_root_block<'a>(&'a self, compilation: &'a Compilation) -> ModuleIdentifier {
pub fn get_root_block<'a>(&'a self, module_graph: &'a ModuleGraph) -> ModuleIdentifier {
match self {
DependenciesBlockIdentifier::Module(m) => *m,
DependenciesBlockIdentifier::AsyncDependenciesBlock(id) => *compilation
.get_module_graph()
DependenciesBlockIdentifier::AsyncDependenciesBlock(id) => *module_graph
.block_by_id(id)
.expect("should have block")
.parent(),
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/build_chunk_graph/incremental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl CodeSplitter {
continue;
};

parent_cg.children.remove(&chunk_group_ukey);
parent_cg.children.swap_remove_full(&chunk_group_ukey);

if let Some(parent_cgi) = self.chunk_group_info_map.get(parent) {
if let Some(parent_cgi) = self.chunk_group_infos.get_mut(parent_cgi) {
Expand Down
7 changes: 7 additions & 0 deletions crates/rspack_core/src/build_chunk_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{incremental::IncrementalPasses, Compilation};

pub(crate) mod code_splitter;
pub(crate) mod incremental;
pub(crate) mod new_code_splitter;

#[instrument(skip_all)]
pub(crate) fn build_chunk_graph(compilation: &mut Compilation) -> rspack_error::Result<()> {
Expand Down Expand Up @@ -46,3 +47,9 @@ pub(crate) fn build_chunk_graph(compilation: &mut Compilation) -> rspack_error::

Ok(())
}

#[instrument(skip_all)]
pub(crate) fn build_chunk_graph_new(compilation: &mut Compilation) -> rspack_error::Result<()> {
new_code_splitter::code_split(compilation)?;
Ok(())
}
Loading

0 comments on commit d4e7793

Please sign in to comment.