Skip to content

Commit

Permalink
feat(lazy-compilation): support module id for LazyCompilationProxyMod…
Browse files Browse the repository at this point in the history
…ule (#9223)
  • Loading branch information
JSerFeng authored Feb 10, 2025
1 parent 2d2ee75 commit 46514f0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 13 additions & 3 deletions crates/rspack_plugin_lazy_compilation/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{path::Path, sync::Arc};
use std::{borrow::Cow, path::Path, sync::Arc};

use cow_utils::CowUtils;
use rspack_cacheable::{cacheable, cacheable_dyn, with::Unsupported};
Expand All @@ -9,8 +9,8 @@ use rspack_core::{
AsyncDependenciesBlock, AsyncDependenciesBlockIdentifier, BoxDependency, BuildContext, BuildInfo,
BuildMeta, BuildResult, ChunkGraph, CodeGenerationData, CodeGenerationResult, Compilation,
ConcatenationScope, Context, DependenciesBlock, DependencyId, DependencyRange, FactoryMeta,
Module, ModuleFactoryCreateData, ModuleIdentifier, ModuleLayer, ModuleType, RuntimeGlobals,
RuntimeSpec, SourceType, TemplateContext,
LibIdentOptions, Module, ModuleFactoryCreateData, ModuleIdentifier, ModuleLayer, ModuleType,
RuntimeGlobals, RuntimeSpec, SourceType, TemplateContext,
};
use rspack_error::{Diagnosable, Diagnostic, Result};
use rspack_plugin_javascript::dependency::CommonJsRequireDependency;
Expand All @@ -35,6 +35,7 @@ pub(crate) struct LazyCompilationProxyModule {

readable_identifier: String,
identifier: ModuleIdentifier,
lib_ident: Option<String>,

blocks: Vec<AsyncDependenciesBlockIdentifier>,
dependencies: Vec<DependencyId>,
Expand All @@ -61,8 +62,10 @@ impl ModuleSourceMapConfig for LazyCompilationProxyModule {
}

impl LazyCompilationProxyModule {
#[allow(clippy::too_many_arguments)]
pub(crate) fn new(
original_module: ModuleIdentifier,
lib_ident: Option<String>,
create_data: ModuleFactoryCreateData,
resource: String,
cacheable: bool,
Expand All @@ -76,12 +79,15 @@ impl LazyCompilationProxyModule {
);
let identifier = format!("lazy-compilation-proxy|{original_module}").into();

let lib_ident = lib_ident.map(|s| format!("{s}!lazy-compilation-proxy"));

Self {
build_info: Default::default(),
build_meta: Default::default(),
cacheable,
create_data,
readable_identifier,
lib_ident,
resource,
identifier,
source_map_kind: SourceMapKind::empty(),
Expand Down Expand Up @@ -133,6 +139,10 @@ impl Module for LazyCompilationProxyModule {
std::borrow::Cow::Borrowed(&self.readable_identifier)
}

fn lib_ident(&self, _options: LibIdentOptions) -> Option<Cow<str>> {
self.lib_ident.as_ref().map(|s| Cow::Borrowed(s.as_str()))
}

fn get_diagnostics(&self) -> Vec<Diagnostic> {
vec![]
}
Expand Down
10 changes: 8 additions & 2 deletions crates/rspack_plugin_lazy_compilation/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use std::{fmt::Debug, sync::Arc};

use rspack_core::{
ApplyContext, BoxModule, Compilation, CompilationId, CompilationParams, CompilerCompilation,
CompilerOptions, DependencyType, EntryDependency, Module, ModuleFactory, ModuleFactoryCreateData,
NormalModuleCreateData, NormalModuleFactoryModule, Plugin, PluginContext,
CompilerOptions, DependencyType, EntryDependency, LibIdentOptions, Module, ModuleFactory,
ModuleFactoryCreateData, NormalModuleCreateData, NormalModuleFactoryModule, Plugin,
PluginContext,
};
use rspack_error::Result;
use rspack_hook::{plugin, plugin_hook};
Expand Down Expand Up @@ -156,6 +157,10 @@ async fn normal_module_factory_module(

let mut backend = self.backend.lock().await;
let module_identifier = module.identifier();

let lib_ident = module.lib_ident(LibIdentOptions {
context: module_factory_create_data.options.context.as_str(),
});
let info = backend
.module(
module_identifier,
Expand All @@ -165,6 +170,7 @@ async fn normal_module_factory_module(

*module = Box::new(LazyCompilationProxyModule::new(
module_identifier,
lib_ident.map(|ident| ident.into_owned()),
module_factory_create_data.clone(),
create_data.resource_resolve_data.resource.clone(),
self.cacheable,
Expand Down

2 comments on commit 46514f0

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 46514f0 Feb 10, 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-10 09af1d8) Current Change
10000_big_production-mode_disable-minimize + exec 37.7 s ± 622 ms 39 s ± 895 ms +3.36 %
10000_development-mode + exec 1.87 s ± 37 ms 1.85 s ± 80 ms -1.10 %
10000_development-mode_hmr + exec 684 ms ± 18 ms 692 ms ± 26 ms +1.23 %
10000_production-mode + exec 2.31 s ± 63 ms 2.26 s ± 43 ms -1.82 %
10000_production-mode_persistent-cold + exec 2.45 s ± 74 ms 2.43 s ± 94 ms -0.75 %
10000_production-mode_persistent-hot + exec 1.64 s ± 26 ms 1.65 s ± 24 ms +0.76 %
arco-pro_development-mode + exec 1.72 s ± 90 ms 1.78 s ± 76 ms +3.59 %
arco-pro_development-mode_hmr + exec 389 ms ± 2.1 ms 388 ms ± 3.2 ms -0.33 %
arco-pro_production-mode + exec 3.62 s ± 212 ms 3.71 s ± 178 ms +2.57 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.67 s ± 262 ms 3.67 s ± 105 ms -0.09 %
arco-pro_production-mode_persistent-cold + exec 3.83 s ± 285 ms 3.87 s ± 114 ms +1.10 %
arco-pro_production-mode_persistent-hot + exec 2.36 s ± 60 ms 2.42 s ± 57 ms +2.53 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.63 s ± 197 ms 3.67 s ± 213 ms +0.90 %
large-dyn-imports_development-mode + exec 2.12 s ± 39 ms 2.14 s ± 179 ms +0.74 %
large-dyn-imports_production-mode + exec 2.14 s ± 20 ms 2.15 s ± 70 ms +0.40 %
threejs_development-mode_10x + exec 1.53 s ± 28 ms 1.54 s ± 43 ms +0.92 %
threejs_development-mode_10x_hmr + exec 783 ms ± 13 ms 787 ms ± 37 ms +0.52 %
threejs_production-mode_10x + exec 5.22 s ± 186 ms 5.2 s ± 78 ms -0.41 %
threejs_production-mode_10x_persistent-cold + exec 5.31 s ± 155 ms 5.34 s ± 321 ms +0.60 %
threejs_production-mode_10x_persistent-hot + exec 4.53 s ± 315 ms 4.5 s ± 146 ms -0.55 %
10000_big_production-mode_disable-minimize + rss memory 8773 MiB ± 74.2 MiB 8733 MiB ± 66 MiB -0.46 %
10000_development-mode + rss memory 653 MiB ± 15.5 MiB 660 MiB ± 8.87 MiB +1.08 %
10000_development-mode_hmr + rss memory 1264 MiB ± 261 MiB 1295 MiB ± 250 MiB +2.45 %
10000_production-mode + rss memory 623 MiB ± 16.1 MiB 634 MiB ± 12.2 MiB +1.68 %
10000_production-mode_persistent-cold + rss memory 743 MiB ± 22.3 MiB 727 MiB ± 26.1 MiB -2.15 %
10000_production-mode_persistent-hot + rss memory 714 MiB ± 18.8 MiB 737 MiB ± 22.3 MiB +3.17 %
arco-pro_development-mode + rss memory 561 MiB ± 21.6 MiB 572 MiB ± 35.4 MiB +1.95 %
arco-pro_development-mode_hmr + rss memory 638 MiB ± 51.3 MiB 673 MiB ± 31.9 MiB +5.53 %
arco-pro_production-mode + rss memory 735 MiB ± 26.9 MiB 716 MiB ± 40.9 MiB -2.65 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 741 MiB ± 13.1 MiB 727 MiB ± 46.1 MiB -1.83 %
arco-pro_production-mode_persistent-cold + rss memory 857 MiB ± 36.2 MiB 844 MiB ± 20.4 MiB -1.55 %
arco-pro_production-mode_persistent-hot + rss memory 730 MiB ± 6.4 MiB 721 MiB ± 19.8 MiB -1.19 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 737 MiB ± 60.8 MiB 716 MiB ± 25.7 MiB -2.95 %
large-dyn-imports_development-mode + rss memory 647 MiB ± 9.25 MiB 644 MiB ± 3.78 MiB -0.36 %
large-dyn-imports_production-mode + rss memory 530 MiB ± 6.21 MiB 528 MiB ± 4.57 MiB -0.44 %
threejs_development-mode_10x + rss memory 551 MiB ± 25.1 MiB 549 MiB ± 8.5 MiB -0.31 %
threejs_development-mode_10x_hmr + rss memory 1124 MiB ± 189 MiB 1164 MiB ± 16.3 MiB +3.54 %
threejs_production-mode_10x + rss memory 829 MiB ± 36.8 MiB 840 MiB ± 16.9 MiB +1.31 %
threejs_production-mode_10x_persistent-cold + rss memory 967 MiB ± 35.8 MiB 950 MiB ± 72.2 MiB -1.79 %
threejs_production-mode_10x_persistent-hot + rss memory 868 MiB ± 38.6 MiB 880 MiB ± 42.5 MiB +1.45 %

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 46514f0 Feb 10, 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 ❌ failure
rspress ✅ success
rslib ✅ success
rsbuild ❌ failure
rsdoctor ❌ failure
examples ✅ success
devserver ✅ success
nuxt ✅ success

Please sign in to comment.