Skip to content

Commit cc47208

Browse files
perf: reduce timing of dervie_entries_aware_chunk_name (#8847)
close #8276
1 parent e6056cf commit cc47208

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

crates/rolldown/src/stages/generate_stage/manual_code_splitting.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::{
77

88
use arcstr::ArcStr;
99
use rolldown_common::{
10-
Chunk, ChunkKind, ChunkingContext, ManualCodeSplittingOptions, MatchGroup, MatchGroupTest,
11-
Module, ModuleIdx, ModuleTable,
10+
Chunk, ChunkKind, ChunkingContext, EntryPoint, ManualCodeSplittingOptions, MatchGroup,
11+
MatchGroupTest, Module, ModuleIdx, ModuleTable,
1212
};
1313
use rolldown_error::BuildResult;
1414
use rolldown_plugin::SharedPluginDriver;
@@ -75,6 +75,7 @@ struct ManualSplitter<'a> {
7575
input_base: &'a ArcStr,
7676
chunk_graph: &'a mut ChunkGraph,
7777
module_to_assigned: &'a mut IndexBitSet<ModuleIdx>,
78+
flattened_entries: Vec<&'a EntryPoint>,
7879
}
7980

8081
impl ManualSplitter<'_> {
@@ -363,7 +364,12 @@ impl ManualSplitter<'_> {
363364
};
364365

365366
let chunk_name = if entries_aware {
366-
derive_entries_aware_chunk_name(&group.name, chunk_bits, self.link_output)
367+
derive_entries_aware_chunk_name(
368+
&group.name,
369+
chunk_bits,
370+
&self.flattened_entries,
371+
self.link_output,
372+
)
367373
} else {
368374
group.name.clone()
369375
};
@@ -428,6 +434,8 @@ impl GenerateStage<'_> {
428434
return Ok(());
429435
}
430436

437+
let flattened_entries: Vec<&EntryPoint> =
438+
self.link_output.entries.iter().flat_map(|(_idx, entries)| entries.iter()).collect();
431439
let mut splitter = ManualSplitter {
432440
link_output: self.link_output,
433441
index_splitting_info,
@@ -438,6 +446,7 @@ impl GenerateStage<'_> {
438446
input_base,
439447
chunk_graph,
440448
module_to_assigned,
449+
flattened_entries,
441450
};
442451
splitter.split().await
443452
}
@@ -720,21 +729,20 @@ fn pick_relevance_split_index(
720729
fn derive_entries_aware_chunk_name(
721730
group_name: &str,
722731
bits: &BitSet,
732+
flattened_entries: &[&EntryPoint],
723733
link_output: &crate::stages::link_stage::LinkStageOutput,
724734
) -> ArcStr {
725735
const MAX_CHUNK_NAME_LEN: usize = 100;
726736
const HASH_DISPLAY_LEN: usize = 8;
727737
const TRUNCATED_LEN: usize = MAX_CHUNK_NAME_LEN - HASH_DISPLAY_LEN - 1; // 1 for the `~` separator
728738

729-
let entry_names: Vec<String> = link_output
730-
.entries
731-
.iter()
732-
.flat_map(|(_idx, entries)| entries.iter())
733-
.enumerate()
734-
.filter_map(|(index, entry_point)| {
735-
if bits.has_bit(index.try_into().unwrap()) {
739+
let entry_names: Vec<String> = bits
740+
.index_of_one()
741+
.filter_map(|index| {
742+
let idx = index as usize;
743+
if idx < flattened_entries.len() {
744+
let entry_point = flattened_entries[idx];
736745
Some(entry_point.name.as_ref().map(ArcStr::to_string).unwrap_or_else(|| {
737-
// Fall back to file stem of the entry module's stable_id
738746
let module = &link_output.module_table[entry_point.idx];
739747
Path::new(module.stable_id().as_str())
740748
.file_stem()

0 commit comments

Comments
 (0)