Skip to content

Commit

Permalink
perf: reuse js module between compilation (#9265)
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind authored Feb 17, 2025
1 parent abb4a0c commit ae99d36
Show file tree
Hide file tree
Showing 122 changed files with 1,583 additions and 1,324 deletions.
137 changes: 56 additions & 81 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ rspack_allocator = { version = "0.2.0", path = "crates/rsp
rspack_ast = { version = "0.2.0", path = "crates/rspack_ast" }
rspack_base64 = { version = "0.2.0", path = "crates/rspack_base64" }
rspack_binding = { version = "0.2.0", path = "crates/rspack_binding" }
rspack_binding_values = { version = "0.2.0", path = "crates/rspack_binding_values" }
rspack_builtin = { version = "0.2.0", path = "crates/rspack_builtin" }
rspack_cacheable = { version = "0.2.0", path = "crates/rspack_cacheable" }
rspack_collection = { version = "0.2.0", path = "crates/rspack_collection" }
Expand Down
65 changes: 62 additions & 3 deletions crates/node_binding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ name = "rspack_node"
publish = false
repository = "https://github.com/web-infra-dev/rspack"
version = "0.2.0"

[lib]
crate-type = ["cdylib"]

[features]
plugin = ["rspack_binding_values/plugin"]
plugin = ["rspack_loader_swc/plugin"]

[dependencies]
anyhow = { workspace = true }
ropey = { workspace = true }
rspack_allocator = { workspace = true }
rspack_binding_values = { workspace = true }
rspack_collections = { workspace = true }
rspack_core = { workspace = true }
rspack_error = { workspace = true }
Expand All @@ -39,11 +39,70 @@ cow-utils = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

napi = { workspace = true }
napi = { workspace = true, features = ["async", "tokio_rt", "serde-json", "anyhow"] }
napi-derive = { workspace = true }

color-backtrace = "0.6.1"

derive_more = { workspace = true, features = ["debug"] }
futures = { workspace = true }
glob = { workspace = true }
heck = { workspace = true }
pollster = { workspace = true }
rspack_cacheable = { workspace = true }
rspack_ids = { workspace = true }
rspack_napi_macros = { workspace = true }
rspack_regex = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
swc_core = { workspace = true, default-features = false, features = ["ecma_transforms_react"] }
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "macros", "test-util", "parking_lot"] }


rspack_loader_lightningcss = { workspace = true }
rspack_loader_preact_refresh = { workspace = true }
rspack_loader_react_refresh = { workspace = true }
rspack_loader_runner = { workspace = true }
rspack_loader_swc = { workspace = true }
rspack_loader_testing = { workspace = true }
rspack_plugin_asset = { workspace = true }
rspack_plugin_banner = { workspace = true }
rspack_plugin_context_replacement = { workspace = true }
rspack_plugin_copy = { workspace = true }
rspack_plugin_css = { workspace = true }
rspack_plugin_devtool = { workspace = true }
rspack_plugin_dll = { workspace = true }
rspack_plugin_dynamic_entry = { workspace = true }
rspack_plugin_ensure_chunk_conditions = { workspace = true }
rspack_plugin_entry = { workspace = true }
rspack_plugin_externals = { workspace = true }
rspack_plugin_extract_css = { workspace = true }
rspack_plugin_hmr = { workspace = true }
rspack_plugin_ignore = { workspace = true }
rspack_plugin_json = { workspace = true }
rspack_plugin_lazy_compilation = { workspace = true }
rspack_plugin_library = { workspace = true }
rspack_plugin_lightning_css_minimizer = { workspace = true }
rspack_plugin_limit_chunk_count = { workspace = true }
rspack_plugin_merge_duplicate_chunks = { workspace = true }
rspack_plugin_mf = { workspace = true }
rspack_plugin_no_emit_on_errors = { workspace = true }
rspack_plugin_progress = { workspace = true }
rspack_plugin_real_content_hash = { workspace = true }
rspack_plugin_remove_duplicate_modules = { workspace = true }
rspack_plugin_remove_empty_chunks = { workspace = true }
rspack_plugin_runtime_chunk = { workspace = true }
rspack_plugin_schemes = { workspace = true }
rspack_plugin_size_limits = { workspace = true }
rspack_plugin_split_chunks = { workspace = true }
rspack_plugin_sri = { workspace = true }
rspack_plugin_swc_js_minimizer = { workspace = true }
rspack_plugin_warn_sensitive_module = { workspace = true }
rspack_plugin_wasm = { workspace = true }
rspack_plugin_web_worker_template = { workspace = true }
rspack_plugin_worker = { workspace = true }


[build-dependencies]
napi-build = { workspace = true }
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl JsChunkGraph {
Ok(
modules
.iter()
.map(|module| JsModuleWrapper::new(module.as_ref(), compilation.id(), Some(compilation)))
.map(|module| JsModuleWrapper::new(module.identifier(), None, compilation.compiler_id()))
.collect::<Vec<_>>(),
)
}
Expand All @@ -59,7 +59,7 @@ impl JsChunkGraph {
modules
.iter()
.filter_map(|module| module_graph.module_by_identifier(module))
.map(|module| JsModuleWrapper::new(module.as_ref(), compilation.id(), Some(compilation)))
.map(|module| JsModuleWrapper::new(module.identifier(), None, compilation.compiler_id()))
.collect::<Vec<_>>(),
)
}
Expand Down Expand Up @@ -114,7 +114,7 @@ impl JsChunkGraph {
SourceType::from(source_type.as_str()),
&compilation.get_module_graph(),
)
.map(|module| JsModuleWrapper::new(module, compilation.id(), Some(compilation)))
.map(|module| JsModuleWrapper::new(module.identifier(), None, compilation.compiler_id()))
.collect(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::{JsChunkWrapper, JsModule, JsModuleWrapper};
#[napi]
pub struct JsChunkGroup {
chunk_group_ukey: ChunkGroupUkey,
compilation_id: CompilationId,
compilation: NonNull<Compilation>,
}

Expand Down Expand Up @@ -71,7 +70,7 @@ impl JsChunkGroup {
js_origins.push(JsChunkGroupOrigin {
module: origin.module.and_then(|module_id| {
compilation.module_by_identifier(&module_id).map(|module| {
JsModuleWrapper::new(module.as_ref(), self.compilation_id, Some(compilation))
JsModuleWrapper::new(module.identifier(), None, compilation.compiler_id())
})
}),
request: match &origin.request {
Expand Down Expand Up @@ -212,7 +211,6 @@ impl ToNapiValue for JsChunkGroupWrapper {
std::collections::hash_map::Entry::Vacant(entry) => {
let js_module = JsChunkGroup {
chunk_group_ukey: val.chunk_group_ukey,
compilation_id: val.compilation_id,
compilation: val.compilation,
};
let r = entry.insert(OneShotRef::new(env, js_module)?);
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl JsCompilation {
.keys()
.filter_map(|module_id| {
compilation.module_by_identifier(module_id).map(|module| {
JsModuleWrapper::new(module.as_ref(), compilation.id(), Some(compilation))
JsModuleWrapper::new(module.identifier(), None, compilation.compiler_id())
})
})
.collect::<Vec<_>>(),
Expand All @@ -197,7 +197,7 @@ impl JsCompilation {
.iter()
.filter_map(|module_id| {
compilation.module_by_identifier(module_id).map(|module| {
JsModuleWrapper::new(module.as_ref(), compilation.id(), Some(compilation))
JsModuleWrapper::new(module.identifier(), None, compilation.compiler_id())
})
})
.collect::<Vec<_>>(),
Expand Down Expand Up @@ -576,23 +576,20 @@ impl JsCompilation {
let compilation = self.as_mut()?;

callbackify(env, f, async {
let compilation_id = compilation.id();
let compiler_id = compilation.compiler_id();

let mut modules = compilation
let modules = compilation
.rebuild_module(
IdentifierSet::from_iter(module_identifiers.into_iter().map(ModuleIdentifier::from)),
|modules| {
modules
.into_iter()
.map(|module| JsModuleWrapper::new(module.as_ref(), compilation_id, None))
.map(|module| JsModuleWrapper::new(module.identifier(), None, compiler_id))
.collect::<Vec<_>>()
},
)
.await
.map_err(|e| Error::new(napi::Status::GenericFailure, format!("{e}")))?;
modules
.iter_mut()
.for_each(|module| module.attach(compilation));

Ok(modules)
})
Expand Down Expand Up @@ -744,7 +741,7 @@ impl JsCompilation {
Some(module) => match module_graph.module_by_identifier(&module.module_identifier) {
Some(module) => {
let js_module =
JsModuleWrapper::new(module.as_ref(), compilation.id(), Some(compilation));
JsModuleWrapper::new(module.identifier(), None, compilation.compiler_id());
(Either::B(()), Either::B(js_module))
}
None => (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

2 comments on commit ae99d36

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on ae99d36 Feb 17, 2025

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 (2025-02-17 85a3aba) Current Change
10000_big_production-mode_disable-minimize + exec 38.9 s ± 489 ms 38.2 s ± 549 ms -1.74 %
10000_development-mode + exec 1.87 s ± 17 ms 1.72 s ± 44 ms -7.76 %
10000_development-mode_hmr + exec 704 ms ± 13 ms 682 ms ± 31 ms -3.18 %
10000_production-mode + exec 2.41 s ± 87 ms 2.17 s ± 48 ms -10.23 %
10000_production-mode_persistent-cold + exec 2.55 s ± 84 ms 2.33 s ± 56 ms -8.58 %
10000_production-mode_persistent-hot + exec 1.73 s ± 46 ms 1.65 s ± 224 ms -4.79 %
arco-pro_development-mode + exec 1.81 s ± 149 ms 1.76 s ± 52 ms -2.54 %
arco-pro_development-mode_hmr + exec 391 ms ± 0.83 ms 384 ms ± 1.9 ms -1.89 %
arco-pro_production-mode + exec 3.75 s ± 103 ms 3.59 s ± 236 ms -4.27 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.83 s ± 152 ms 3.65 s ± 212 ms -4.61 %
arco-pro_production-mode_persistent-cold + exec 3.86 s ± 131 ms 3.7 s ± 87 ms -4.24 %
arco-pro_production-mode_persistent-hot + exec 2.51 s ± 206 ms 2.33 s ± 149 ms -7.10 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.72 s ± 186 ms 3.59 s ± 155 ms -3.50 %
large-dyn-imports_development-mode + exec 2.1 s ± 68 ms 1.99 s ± 54 ms -5.30 %
large-dyn-imports_production-mode + exec 2.16 s ± 34 ms 2.04 s ± 41 ms -5.28 %
threejs_development-mode_10x + exec 1.6 s ± 42 ms 1.52 s ± 16 ms -5.06 %
threejs_development-mode_10x_hmr + exec 834 ms ± 28 ms 787 ms ± 34 ms -5.69 %
threejs_production-mode_10x + exec 5.49 s ± 238 ms 5.18 s ± 255 ms -5.56 %
threejs_production-mode_10x_persistent-cold + exec 5.59 s ± 373 ms 5.26 s ± 294 ms -5.96 %
threejs_production-mode_10x_persistent-hot + exec 4.72 s ± 222 ms 4.51 s ± 202 ms -4.49 %
10000_big_production-mode_disable-minimize + rss memory 8689 MiB ± 61.4 MiB 8680 MiB ± 34.3 MiB -0.10 %
10000_development-mode + rss memory 635 MiB ± 26.3 MiB 685 MiB ± 39.6 MiB +7.84 %
10000_development-mode_hmr + rss memory 1283 MiB ± 216 MiB 1347 MiB ± 148 MiB +4.99 %
10000_production-mode + rss memory 616 MiB ± 14.1 MiB 673 MiB ± 27.1 MiB +9.27 %
10000_production-mode_persistent-cold + rss memory 736 MiB ± 6.99 MiB 774 MiB ± 14.1 MiB +5.04 %
10000_production-mode_persistent-hot + rss memory 714 MiB ± 9.4 MiB 717 MiB ± 23.4 MiB +0.47 %
arco-pro_development-mode + rss memory 571 MiB ± 28.2 MiB 623 MiB ± 10.8 MiB +9.20 %
arco-pro_development-mode_hmr + rss memory 658 MiB ± 88.1 MiB 697 MiB ± 81.4 MiB +5.86 %
arco-pro_production-mode + rss memory 729 MiB ± 30.7 MiB 738 MiB ± 22.2 MiB +1.21 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 728 MiB ± 20.1 MiB 746 MiB ± 14.2 MiB +2.48 %
arco-pro_production-mode_persistent-cold + rss memory 854 MiB ± 16.2 MiB 809 MiB ± 61.1 MiB -5.24 %
arco-pro_production-mode_persistent-hot + rss memory 718 MiB ± 30.1 MiB 706 MiB ± 52.5 MiB -1.65 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 719 MiB ± 27.4 MiB 731 MiB ± 29.4 MiB +1.65 %
large-dyn-imports_development-mode + rss memory 641 MiB ± 7.68 MiB 661 MiB ± 8.94 MiB +3.18 %
large-dyn-imports_production-mode + rss memory 522 MiB ± 6.17 MiB 546 MiB ± 1.62 MiB +4.70 %
threejs_development-mode_10x + rss memory 548 MiB ± 15.1 MiB 556 MiB ± 10.9 MiB +1.40 %
threejs_development-mode_10x_hmr + rss memory 1179 MiB ± 36.7 MiB 1155 MiB ± 218 MiB -2.02 %
threejs_production-mode_10x + rss memory 834 MiB ± 32.9 MiB 833 MiB ± 17.7 MiB -0.19 %
threejs_production-mode_10x_persistent-cold + rss memory 955 MiB ± 69.6 MiB 914 MiB ± 64.3 MiB -4.27 %
threejs_production-mode_10x_persistent-hot + rss memory 862 MiB ± 42.4 MiB 807 MiB ± 39 MiB -6.43 %

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on ae99d36 Feb 17, 2025

Choose a reason for hiding this comment

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

📝 Ecosystem CI detail: Open

suite result
modernjs ✅ success
rspress ✅ success
rslib ✅ success
rsbuild ❌ failure
rsdoctor ❌ failure
examples ✅ success
devserver ❌ failure
nuxt ✅ success

Please sign in to comment.