Skip to content

Commit

Permalink
refactor: move module_argument and exports_argument to BuildInfo stru…
Browse files Browse the repository at this point in the history
…ct (#9260)
  • Loading branch information
inottn authored Feb 14, 2025
1 parent 4360458 commit 99709d1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 34 deletions.
2 changes: 0 additions & 2 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,6 @@ export interface JsBuildMeta {
esm: boolean
exportsType: 'unset' | 'default' | 'namespace' | 'flagged' | 'dynamic'
defaultObject: 'false' | 'redirect' | JsBuildMetaDefaultObjectRedirectWarn
moduleArgument: 'module' | 'webpackModule'
exportsArgument: 'exports' | 'webpackExports'
sideEffectFree?: boolean
exportsFinalName?: Array<[string, string]> | undefined
}
Expand Down
23 changes: 1 addition & 22 deletions crates/rspack_binding_values/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use napi_derive::napi;
use rspack_collections::IdentifierMap;
use rspack_core::{
BuildMeta, BuildMetaDefaultObject, BuildMetaExportsType, Compilation, CompilationAsset,
CompilationId, ExportsArgument, LibIdentOptions, Module, ModuleArgument, ModuleIdentifier,
RuntimeModuleStage, SourceType,
CompilationId, LibIdentOptions, Module, ModuleIdentifier, RuntimeModuleStage, SourceType,
};
use rspack_napi::{
napi::bindgen_prelude::*, threadsafe_function::ThreadsafeFunction, OneShotInstanceRef,
Expand Down Expand Up @@ -516,10 +515,6 @@ pub struct JsBuildMeta {
pub exports_type: String,
#[napi(ts_type = "'false' | 'redirect' | JsBuildMetaDefaultObjectRedirectWarn")]
pub default_object: JsBuildMetaDefaultObject,
#[napi(ts_type = "'module' | 'webpackModule'")]
pub module_argument: String,
#[napi(ts_type = "'exports' | 'webpackExports'")]
pub exports_argument: String,
pub side_effect_free: Option<bool>,
#[napi(ts_type = "Array<[string, string]> | undefined")]
pub exports_final_name: Option<Vec<Vec<String>>>,
Expand All @@ -531,9 +526,7 @@ impl From<JsBuildMeta> for BuildMeta {
strict_esm_module,
has_top_level_await,
esm,
exports_argument: raw_exports_argument,
default_object: raw_default_object,
module_argument: raw_module_argument,
exports_final_name: raw_exports_final_name,
side_effect_free,
exports_type: raw_exports_type,
Expand All @@ -559,18 +552,6 @@ impl From<JsBuildMeta> for BuildMeta {
_ => unreachable!(),
};

let module_argument = match raw_module_argument.as_str() {
"module" => ModuleArgument::Module,
"webpackModule" => ModuleArgument::WebpackModule,
_ => unreachable!(),
};

let exports_argument = match raw_exports_argument.as_str() {
"exports" => ExportsArgument::Exports,
"webpackExports" => ExportsArgument::WebpackExports,
_ => unreachable!(),
};

let exports_final_name = raw_exports_final_name.map(|exports_name| {
exports_name
.into_iter()
Expand All @@ -594,8 +575,6 @@ impl From<JsBuildMeta> for BuildMeta {
esm,
exports_type,
default_object,
module_argument,
exports_argument,
side_effect_free,
exports_final_name,
}
Expand Down
16 changes: 12 additions & 4 deletions crates/rspack_core/src/concatenated_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ use crate::{
CodeGenerationExportsFinalNames, CodeGenerationPublicPathAutoReplace, CodeGenerationResult,
Compilation, ConcatenatedModuleIdent, ConcatenationScope, ConnectionState, Context,
DependenciesBlock, DependencyId, DependencyTemplate, DependencyType, ErrorSpan,
ExportInfoProvided, ExportsType, FactoryMeta, IdentCollector, LibIdentOptions,
MaybeDynamicTargetExportInfoHashKey, Module, ModuleDependency, ModuleGraph,
ExportInfoProvided, ExportsArgument, ExportsType, FactoryMeta, IdentCollector, LibIdentOptions,
MaybeDynamicTargetExportInfoHashKey, Module, ModuleArgument, ModuleDependency, ModuleGraph,
ModuleGraphConnection, ModuleIdentifier, ModuleLayer, ModuleType, Resolve, RuntimeCondition,
RuntimeGlobals, RuntimeSpec, SourceType, SpanExt, Template, UsageState, UsedName, DEFAULT_EXPORT,
NAMESPACE_OBJECT_EXPORT,
Expand Down Expand Up @@ -78,6 +78,8 @@ pub struct RootModuleContext {
pub side_effect_connection_state: ConnectionState,
pub factory_meta: Option<FactoryMeta>,
pub build_meta: BuildMeta,
pub exports_argument: ExportsArgument,
pub module_argument: ModuleArgument,
}

#[allow(unused)]
Expand Down Expand Up @@ -386,6 +388,11 @@ impl ConcatenatedModule {
) -> Self {
// make the hash consistent
modules.sort_by(|a, b| a.id.cmp(&b.id));
let RootModuleContext {
module_argument,
exports_argument,
..
} = root_module_ctxt;
Self {
id,
root_module_ctxt,
Expand All @@ -397,8 +404,9 @@ impl ConcatenatedModule {
diagnostics: vec![],
build_info: BuildInfo {
cacheable: true,
hash: None,
strict: true,
module_argument,
exports_argument,
top_level_declarations: Some(Default::default()),
..Default::default()
},
Expand Down Expand Up @@ -1005,7 +1013,7 @@ impl Module for ConcatenatedModule {
));
}

let exports_argument = self.build_meta().exports_argument;
let exports_argument = self.get_exports_argument();

let should_skip_render_definitions = compilation
.plugin_driver
Expand Down
10 changes: 6 additions & 4 deletions crates/rspack_core/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub struct BuildInfo {
pub cacheable: bool,
pub hash: Option<RspackHashDigest>,
pub strict: bool,
pub module_argument: ModuleArgument,
pub exports_argument: ExportsArgument,
pub file_dependencies: HashSet<ArcPath>,
pub context_dependencies: HashSet<ArcPath>,
pub missing_dependencies: HashSet<ArcPath>,
Expand All @@ -77,6 +79,8 @@ impl Default for BuildInfo {
cacheable: true,
hash: None,
strict: false,
module_argument: Default::default(),
exports_argument: Default::default(),
file_dependencies: HashSet::default(),
context_dependencies: HashSet::default(),
missing_dependencies: HashSet::default(),
Expand Down Expand Up @@ -175,8 +179,6 @@ pub struct BuildMeta {
pub esm: bool,
pub exports_type: BuildMetaExportsType,
pub default_object: BuildMetaDefaultObject,
pub module_argument: ModuleArgument,
pub exports_argument: ExportsArgument,
#[serde(skip_serializing_if = "Option::is_none")]
pub side_effect_free: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -253,11 +255,11 @@ pub trait Module:
fn build_meta_mut(&mut self) -> &mut BuildMeta;

fn get_exports_argument(&self) -> ExportsArgument {
self.build_meta().exports_argument
self.build_info().exports_argument
}

fn get_module_argument(&self) -> ModuleArgument {
self.build_meta().module_argument
self.build_info().module_argument
}

fn get_exports_type(&self, module_graph: &ModuleGraph, strict: bool) -> ExportsType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ impl JavascriptParserPlugin for ESMDetectionParserPlugin {
parser.build_meta.esm = true;
parser.build_meta.exports_type = BuildMetaExportsType::Namespace;
parser.build_info.strict = true;
parser.build_meta.exports_argument = ExportsArgument::WebpackExports;
parser.build_info.exports_argument = ExportsArgument::WebpackExports;
}

if is_strict_esm {
parser.build_meta.strict_esm_module = true;
parser.build_meta.module_argument = ModuleArgument::WebpackModule;
parser.build_info.module_argument = ModuleArgument::WebpackModule;
}

None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ impl ModuleConcatenationPlugin {
.get_side_effects_connection_state(&module_graph, &mut IdentifierSet::default()),
factory_meta: box_module.factory_meta().cloned(),
build_meta: box_module.build_meta().clone(),
module_argument: box_module.get_module_argument(),
exports_argument: box_module.get_exports_argument(),
};
let modules = modules_set
.iter()
Expand Down

2 comments on commit 99709d1

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 99709d1 Feb 14, 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-14 05524cd) Current Change
10000_big_production-mode_disable-minimize + exec 37.9 s ± 263 ms 39 s ± 352 ms +2.90 %
10000_development-mode + exec 1.83 s ± 21 ms 1.87 s ± 175 ms +1.84 %
10000_development-mode_hmr + exec 680 ms ± 7.1 ms 694 ms ± 24 ms +1.96 %
10000_production-mode + exec 2.29 s ± 68 ms 2.32 s ± 177 ms +1.63 %
10000_production-mode_persistent-cold + exec 2.44 s ± 66 ms 2.44 s ± 29 ms +0.11 %
10000_production-mode_persistent-hot + exec 1.68 s ± 135 ms 1.66 s ± 44 ms -1.28 %
arco-pro_development-mode + exec 1.8 s ± 164 ms 1.74 s ± 145 ms -3.06 %
arco-pro_development-mode_hmr + exec 388 ms ± 1.9 ms 387 ms ± 0.9 ms -0.24 %
arco-pro_production-mode + exec 3.6 s ± 123 ms 3.67 s ± 325 ms +1.87 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.63 s ± 134 ms 3.72 s ± 115 ms +2.39 %
arco-pro_production-mode_persistent-cold + exec 3.79 s ± 176 ms 3.94 s ± 415 ms +4.12 %
arco-pro_production-mode_persistent-hot + exec 2.37 s ± 75 ms 2.42 s ± 77 ms +2.25 %
arco-pro_production-mode_traverse-chunk-modules + exec 3.62 s ± 183 ms 3.72 s ± 199 ms +2.74 %
large-dyn-imports_development-mode + exec 2.12 s ± 18 ms 2.11 s ± 89 ms -0.13 %
large-dyn-imports_production-mode + exec 2.15 s ± 48 ms 2.16 s ± 35 ms +0.06 %
threejs_development-mode_10x + exec 1.58 s ± 69 ms 1.57 s ± 120 ms -0.79 %
threejs_development-mode_10x_hmr + exec 785 ms ± 7.9 ms 784 ms ± 24 ms -0.05 %
threejs_production-mode_10x + exec 5.25 s ± 50 ms 5.27 s ± 264 ms +0.50 %
threejs_production-mode_10x_persistent-cold + exec 5.31 s ± 95 ms 5.36 s ± 314 ms +0.95 %
threejs_production-mode_10x_persistent-hot + exec 4.52 s ± 102 ms 4.53 s ± 303 ms +0.31 %
10000_big_production-mode_disable-minimize + rss memory 8704 MiB ± 49.5 MiB 8717 MiB ± 63.2 MiB +0.15 %
10000_development-mode + rss memory 636 MiB ± 27.9 MiB 652 MiB ± 28.3 MiB +2.38 %
10000_development-mode_hmr + rss memory 1223 MiB ± 158 MiB 1292 MiB ± 133 MiB +5.68 %
10000_production-mode + rss memory 628 MiB ± 14.1 MiB 634 MiB ± 32.7 MiB +1.00 %
10000_production-mode_persistent-cold + rss memory 735 MiB ± 12.5 MiB 741 MiB ± 13.1 MiB +0.81 %
10000_production-mode_persistent-hot + rss memory 719 MiB ± 3.87 MiB 724 MiB ± 22.9 MiB +0.62 %
arco-pro_development-mode + rss memory 583 MiB ± 24.4 MiB 572 MiB ± 35.7 MiB -1.97 %
arco-pro_development-mode_hmr + rss memory 644 MiB ± 77 MiB 664 MiB ± 54.7 MiB +3.01 %
arco-pro_production-mode + rss memory 724 MiB ± 7.62 MiB 711 MiB ± 25.9 MiB -1.76 %
arco-pro_production-mode_generate-package-json-webpack-plugin + rss memory 728 MiB ± 15.8 MiB 739 MiB ± 29.3 MiB +1.52 %
arco-pro_production-mode_persistent-cold + rss memory 843 MiB ± 21.6 MiB 839 MiB ± 41.5 MiB -0.50 %
arco-pro_production-mode_persistent-hot + rss memory 710 MiB ± 22.1 MiB 704 MiB ± 23.9 MiB -0.89 %
arco-pro_production-mode_traverse-chunk-modules + rss memory 709 MiB ± 8.18 MiB 718 MiB ± 58.3 MiB +1.22 %
large-dyn-imports_development-mode + rss memory 643 MiB ± 3.77 MiB 642 MiB ± 4.79 MiB -0.21 %
large-dyn-imports_production-mode + rss memory 525 MiB ± 6.6 MiB 528 MiB ± 8.48 MiB +0.52 %
threejs_development-mode_10x + rss memory 552 MiB ± 18.3 MiB 541 MiB ± 30.3 MiB -2.09 %
threejs_development-mode_10x_hmr + rss memory 1105 MiB ± 90.1 MiB 1184 MiB ± 41.4 MiB +7.12 %
threejs_production-mode_10x + rss memory 841 MiB ± 33 MiB 819 MiB ± 12.5 MiB -2.54 %
threejs_production-mode_10x_persistent-cold + rss memory 968 MiB ± 36.3 MiB 953 MiB ± 52.1 MiB -1.53 %
threejs_production-mode_10x_persistent-hot + rss memory 866 MiB ± 43.1 MiB 865 MiB ± 56.5 MiB -0.15 %

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented on 99709d1 Feb 14, 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.