Skip to content

Commit

Permalink
perf: init
Browse files Browse the repository at this point in the history
  • Loading branch information
h-a-n-a committed Jul 23, 2024
1 parent 719c3de commit 9c40c17
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 27 deletions.
6 changes: 3 additions & 3 deletions crates/rspack_core/src/compiler/make/repair/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ impl Task<MakeTaskContext> for BuildResultTask {
let mut queue = VecDeque::new();
let mut all_dependencies = vec![];
let mut handle_block = |dependencies: Vec<BoxDependency>,
blocks: Vec<AsyncDependenciesBlock>,
current_block: Option<AsyncDependenciesBlock>|
-> Vec<AsyncDependenciesBlock> {
blocks: Vec<Box<AsyncDependenciesBlock>>,
current_block: Option<Box<AsyncDependenciesBlock>>|
-> Vec<Box<AsyncDependenciesBlock>> {
for dependency in dependencies {
let dependency_id = *dependency.id();
if current_block.is_none() {
Expand Down
9 changes: 6 additions & 3 deletions crates/rspack_core/src/context_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,10 @@ impl ContextModule {
Ok(())
}

fn resolve_dependencies(&self) -> Result<(Vec<BoxDependency>, Vec<AsyncDependenciesBlock>)> {
// Vec<Box<T: Sized>> makes sense if T is a large type (see #3530, 1st comment).
// #3530: https://github.com/rust-lang/rust-clippy/issues/3530
#[allow(clippy::vec_box)]
fn resolve_dependencies(&self) -> Result<(Vec<BoxDependency>, Vec<Box<AsyncDependenciesBlock>>)> {
tracing::trace!("resolving context module path {}", self.options.resource);

let resolver = &self.resolve_factory.get(ResolveOptionsWithDependencyType {
Expand Down Expand Up @@ -1133,7 +1136,7 @@ impl ContextModule {
if let Some(group_options) = &self.options.context_options.group_options {
block.set_group_options(group_options.clone());
}
blocks.push(block);
blocks.push(Box::new(block));
} else if matches!(self.options.context_options.mode, ContextMode::Lazy) {
let mut index = 0;
for context_element_dependency in context_element_dependencies {
Expand Down Expand Up @@ -1175,7 +1178,7 @@ impl ContextModule {
prefetch_order,
fetch_priority,
)));
blocks.push(block);
blocks.push(Box::new(block));
}
} else {
dependencies = context_element_dependencies
Expand Down
7 changes: 5 additions & 2 deletions crates/rspack_core/src/dependencies_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ impl From<String> for AsyncDependenciesBlockIdentifier {
pub struct AsyncDependenciesBlock {
id: AsyncDependenciesBlockIdentifier,
group_options: Option<GroupOptions>,
blocks: Vec<AsyncDependenciesBlock>,
// Vec<Box<T: Sized>> makes sense if T is a large type (see #3530, 1st comment).
// #3530: https://github.com/rust-lang/rust-clippy/issues/3530
#[allow(clippy::vec_box)]
blocks: Vec<Box<AsyncDependenciesBlock>>,
block_ids: Vec<AsyncDependenciesBlockIdentifier>,
dependency_ids: Vec<DependencyId>,
dependencies: Vec<BoxDependency>,
Expand Down Expand Up @@ -164,7 +167,7 @@ impl AsyncDependenciesBlock {
// self.blocks.push(block);
}

pub fn take_blocks(&mut self) -> Vec<AsyncDependenciesBlock> {
pub fn take_blocks(&mut self) -> Vec<Box<AsyncDependenciesBlock>> {
std::mem::take(&mut self.blocks)
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub struct BuildResult {
pub build_meta: BuildMeta,
pub build_info: BuildInfo,
pub dependencies: Vec<BoxDependency>,
pub blocks: Vec<AsyncDependenciesBlock>,
pub blocks: Vec<Box<AsyncDependenciesBlock>>,
pub optimization_bailouts: Vec<String>,
}

Expand Down
9 changes: 6 additions & 3 deletions crates/rspack_core/src/module_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub struct ModuleGraphPartial {
dependencies: HashMap<DependencyId, Option<BoxDependency>>,

/// AsyncDependenciesBlocks indexed by `AsyncDependenciesBlockIdentifier`.
blocks: HashMap<AsyncDependenciesBlockIdentifier, Option<AsyncDependenciesBlock>>,
blocks: HashMap<AsyncDependenciesBlockIdentifier, Option<Box<AsyncDependenciesBlock>>>,

/// ModuleGraphModule indexed by `ModuleIdentifier`.
module_graph_modules: IdentifierMap<Option<ModuleGraphModule>>,
Expand Down Expand Up @@ -601,7 +601,7 @@ impl<'a> ModuleGraph<'a> {
}
}

pub fn add_block(&mut self, block: AsyncDependenciesBlock) {
pub fn add_block(&mut self, block: Box<AsyncDependenciesBlock>) {
let Some(active_partial) = &mut self.active else {
panic!("should have active partial");
};
Expand Down Expand Up @@ -641,7 +641,10 @@ impl<'a> ModuleGraph<'a> {
&self,
block_id: &AsyncDependenciesBlockIdentifier,
) -> Option<&AsyncDependenciesBlock> {
self.loop_partials(|p| p.blocks.get(block_id))?.as_ref()
self
.loop_partials(|p| p.blocks.get(block_id))?
.as_ref()
.map(|b| &**b)
}

pub fn block_by_id_expect(
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/parser_and_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl SideEffectsBailoutItemWithSpan {
#[derive(Debug)]
pub struct ParseResult {
pub dependencies: Vec<BoxDependency>,
pub blocks: Vec<AsyncDependenciesBlock>,
pub blocks: Vec<Box<AsyncDependenciesBlock>>,
pub presentational_dependencies: Vec<Box<dyn DependencyTemplate>>,
pub code_generation_dependencies: Vec<Box<dyn ModuleDependency>>,
pub source: BoxSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl JavascriptParserPlugin for ImportParserPlugin {
chunk_prefetch,
fetch_priority,
)));
parser.blocks.push(block);
parser.blocks.push(Box::new(block));
Some(true)
} else {
let ContextModuleScanResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn add_dependencies(
depend_on: None,
})));

parser.blocks.push(block);
parser.blocks.push(Box::new(block));
if let Some(range) = range {
parser
.presentational_dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::BoxJavascriptParserPlugin;

pub struct ScanDependenciesResult {
pub dependencies: Vec<BoxDependency>,
pub blocks: Vec<AsyncDependenciesBlock>,
pub blocks: Vec<Box<AsyncDependenciesBlock>>,
pub presentational_dependencies: Vec<BoxDependencyTemplate>,
pub warning_diagnostics: Vec<Box<dyn Diagnostic + Send + Sync>>,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub struct JavascriptParser<'parser> {
pub(crate) warning_diagnostics: Vec<Box<dyn Diagnostic + Send + Sync>>,
pub dependencies: Vec<BoxDependency>,
pub(crate) presentational_dependencies: Vec<Box<dyn DependencyTemplate>>,
pub(crate) blocks: Vec<AsyncDependenciesBlock>,
pub(crate) blocks: Vec<Box<AsyncDependenciesBlock>>,
// TODO: remove `additional_data` once we have builtin:css-extract-loader
pub additional_data: AdditionalData,
pub(crate) comments: Option<&'parser dyn Comments>,
Expand Down Expand Up @@ -262,11 +262,11 @@ impl<'parser> JavascriptParser<'parser> {
parser_plugins: &'parser mut Vec<BoxJavascriptParserPlugin>,
additional_data: AdditionalData,
) -> Self {
let warning_diagnostics: Vec<Box<dyn Diagnostic + Send + Sync>> = Vec::with_capacity(32);
let errors = Vec::with_capacity(32);
let dependencies = Vec::with_capacity(256);
let blocks = Vec::with_capacity(256);
let presentational_dependencies = Vec::with_capacity(256);
let warning_diagnostics: Vec<Box<dyn Diagnostic + Send + Sync>> = Vec::with_capacity(4);
let errors = Vec::with_capacity(4);
let dependencies = Vec::with_capacity(64);
let blocks = Vec::with_capacity(64);
let presentational_dependencies = Vec::with_capacity(64);
let parser_exports_state: Option<bool> = None;

let mut plugins: Vec<parser_plugin::BoxJavascriptParserPlugin> = Vec::with_capacity(32);
Expand Down
5 changes: 5 additions & 0 deletions crates/rspack_plugin_javascript/src/visitors/scope_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ pub struct ScopeInfoDB {
tag_info_db: TagInfoDB,
}

#[test]
fn test() {
dbg!(size_of::<ScopeInfoDB>());
}

impl Default for ScopeInfoDB {
fn default() -> Self {
Self::new()
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_plugin_lazy_compilation/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ impl Module for LazyCompilationProxyModule {
if self.active {
let dep = LazyCompilationDependency::new(self.create_data.clone());

blocks.push(AsyncDependenciesBlock::new(
blocks.push(Box::new(AsyncDependenciesBlock::new(
self.identifier,
None,
None,
vec![Box::new(dep)],
None,
));
)));
}

let mut files = FxHashSet::default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Module for ContainerEntryModule {
block.set_group_options(GroupOptions::ChunkGroup(
ChunkGroupOptions::default().name_optional(options.name.clone()),
));
blocks.push(block);
blocks.push(Box::new(block));
}
dependencies.push(Box::new(StaticExportsDependency::new(
StaticExportsSpec::Array(vec!["get".into(), "init".into()]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl Module for ConsumeSharedModule {
dependencies.push(dep as BoxDependency);
} else {
let block = AsyncDependenciesBlock::new(self.identifier, None, None, vec![dep], None);
blocks.push(block);
blocks.push(Box::new(block));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl Module for ProvideSharedModule {
dependencies.push(dep as BoxDependency);
} else {
let block = AsyncDependenciesBlock::new(self.identifier, None, None, vec![dep], None);
blocks.push(block);
blocks.push(Box::new(block));
}

Ok(BuildResult {
Expand Down

0 comments on commit 9c40c17

Please sign in to comment.