Skip to content

Comments

refactor: move ineffective dynamic import detection into pre_rendered_chunk generation#8295

Draft
shulaoda wants to merge 2 commits intomainfrom
02-12-refactor_move_ineffective_dynamic_import_detection_into_pre_rendered_chunk_generation
Draft

refactor: move ineffective dynamic import detection into pre_rendered_chunk generation#8295
shulaoda wants to merge 2 commits intomainfrom
02-12-refactor_move_ineffective_dynamic_import_detection_into_pre_rendered_chunk_generation

Conversation

@shulaoda
Copy link
Member

@shulaoda shulaoda commented Feb 12, 2026

@shulaoda Can we emit this warning when we optimize the output (convert the dynamic import into a static import)?

Do you mean at the stage where they are merged into one chunk?

I think yes. I was thinking of the place we don't have to re-calculate the information.

If I’m not mistaken, this effectively avoids iterating over chunk_graph.chunk_table.iter(), right? I’ll follow up with another PR to improve it further.

Yes, doing it in a follow up PR is ok.

_Originally posted by @sapphi-red in #8284 (comment)

Copy link
Member Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label graphite: merge-when-ready to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@shulaoda shulaoda requested a review from sapphi-red February 12, 2026 11:30
@shulaoda shulaoda marked this pull request as ready for review February 12, 2026 11:32
@github-actions
Copy link
Contributor

Benchmarks Rust

  • target: 02-12-refactor_move_esm_format_check_into_determine_export_mode(37c7a74)
  • pr: 02-12-refactor_move_ineffective_dynamic_import_detection_into_pre_rendered_chunk_generation(0472410)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.00     73.1±2.65ms        ? ?/sec    1.02     74.5±2.48ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.00     79.5±3.16ms        ? ?/sec    1.01     79.9±2.56ms        ? ?/sec
bundle/bundle@rome_ts                                        1.02    104.7±4.09ms        ? ?/sec    1.00    102.7±2.31ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.00    114.4±2.49ms        ? ?/sec    1.00    114.8±2.46ms        ? ?/sec
bundle/bundle@threejs                                        1.02     36.6±1.04ms        ? ?/sec    1.00     36.0±0.83ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.03     42.2±0.88ms        ? ?/sec    1.00     41.1±0.76ms        ? ?/sec
bundle/bundle@threejs10x                                     1.01    373.5±6.37ms        ? ?/sec    1.00   371.0±10.25ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.01    430.6±6.86ms        ? ?/sec    1.00    426.6±6.34ms        ? ?/sec
scan/scan@rome_ts                                            1.00     79.6±1.64ms        ? ?/sec    1.02     81.3±2.29ms        ? ?/sec
scan/scan@threejs                                            1.00     27.8±1.68ms        ? ?/sec    1.01     28.0±0.57ms        ? ?/sec
scan/scan@threejs10x                                         1.00    281.5±5.05ms        ? ?/sec    1.02    287.8±5.45ms        ? ?/sec

@graphite-app graphite-app bot changed the base branch from 02-12-refactor_move_esm_format_check_into_determine_export_mode to graphite-base/8295 February 12, 2026 11:59
@sapphi-red
Copy link
Member

This still iterates over the modules in each chunk.
I was thinking of doing it here:

if is_importer_importee_in_same_chunk {

I guess we can avoid iterating if we do it here.

@shulaoda shulaoda marked this pull request as draft February 12, 2026 12:04
@graphite-app graphite-app bot force-pushed the 02-12-refactor_move_ineffective_dynamic_import_detection_into_pre_rendered_chunk_generation branch from 0472410 to e1ead38 Compare February 12, 2026 12:15
@graphite-app graphite-app bot force-pushed the graphite-base/8295 branch from 37c7a74 to 79e6ccf Compare February 12, 2026 12:15
@graphite-app graphite-app bot changed the base branch from graphite-base/8295 to main February 12, 2026 12:16
@graphite-app graphite-app bot force-pushed the 02-12-refactor_move_ineffective_dynamic_import_detection_into_pre_rendered_chunk_generation branch from e1ead38 to 93b5148 Compare February 12, 2026 12:16
@netlify
Copy link

netlify bot commented Feb 12, 2026

Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 93b5148
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/698dc4870b5fca0008a67e80

@shulaoda
Copy link
Member Author

shulaoda commented Feb 12, 2026

This still iterates over the modules in each chunk. I was thinking of doing it here:

if is_importer_importee_in_same_chunk {

I guess we can avoid iterating if we do it here.

I’ve identified some limitations. The logic below makes it difficult for us to expose the warnings. To achieve the intended behavior, we might need to refactor parts of the current implementation. I’m not sure whether it’s worth the effort. I will try it.

let ast_table_iter = self.link_output.ast_table.par_iter_mut_enumerated();
ast_table_iter
.filter(|(idx, _ast)| {
self.link_output.module_table[*idx]
.as_normal()
.is_some_and(|m| self.link_output.metas[m.idx].is_included)
})
.filter_map(|(idx, ast)| {
let ast = ast.as_mut()?;
let module = self.link_output.module_table[idx].as_normal().unwrap();
let ast_scope = &self.link_output.symbol_db[idx].as_ref().unwrap().ast_scopes;
let chunk_idx = chunk_graph.module_to_chunk[idx].unwrap();
let chunk = &chunk_graph.chunk_table[chunk_idx];
let linking_info = &self.link_output.metas[module.idx];
let ctx = ScopeHoistingFinalizerContext {
idx,
chunk,
chunk_idx,
symbol_db: &self.link_output.symbol_db,
linking_info,
module,
modules: &self.link_output.module_table.modules,
linking_infos: &self.link_output.metas,
runtime: &self.link_output.runtime,
chunk_graph: &chunk_graph,
options: self.options,
file_emitter: &self.plugin_driver.file_emitter,
constant_value_map: &self.link_output.global_constant_symbol_map,
side_effect_free_function_symbols: &side_effect_free_function_symbols,
safely_merge_cjs_ns_map: &self.link_output.safely_merge_cjs_ns_map,
used_symbol_refs: &self.link_output.used_symbol_refs,
};
let mutable_state = FinalizerMutableState {
cur_stmt_index: 0,
keep_name_statement_to_insert: Vec::new(),
needs_hosted_top_level_binding: false,
module_namespace_included: self
.link_output
.used_symbol_refs
.contains(&module.namespace_object_ref),
transferred_import_record: chunk
.remove_map
.get(&module.idx)
.cloned()
.map(|idxs| {
idxs.into_iter().map(|idx| (idx, String::new())).collect::<FxIndexMap<_, _>>()
})
.unwrap_or_default(),
rendered_concatenated_wrapped_module_parts: RenderedConcatenatedModuleParts::default(),
};
let concatenated_wrapped_module_kind = ctx.linking_info.concatenated_wrapped_module_kind;
let (transferred_import_record, rendered_concatenated_wrapped_module_parts) =
ctx.finalize_normal_module(ast, ast_scope, mutable_state);
(!transferred_import_record.is_empty()
|| !matches!(concatenated_wrapped_module_kind, ConcatenateWrappedModuleKind::None))
.then_some((idx, transferred_import_record, rendered_concatenated_wrapped_module_parts))
})
.collect::<Vec<_>>()
});

@sapphi-red
Copy link
Member

If it's difficult, it's also ok to keep it as-is 👍

graphite-app bot pushed a commit that referenced this pull request Feb 12, 2026
…#8301)

Prepare for #8295,  extract related logic into a separate module to prevent `mod.rs` from becoming too bloated.
shulaoda added a commit that referenced this pull request Feb 12, 2026
Prepare for #8295, extract related logic into the `finalize_modules` module to keep `mod.rs` focused
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants