Skip to content

perf: repeated canonical_ref + namespace_alias lookup in compute_cross_chunk_links #8633

@Boshen

Description

@Boshen

Context

In crates/rolldown/src/stages/generate_stage/compute_cross_chunk_links.rs:237-282, the same 3-step canonical ref resolution pattern is duplicated 4 times within collect_depended_symbols:

// Pattern repeated 4 times:
let mut canonical_ref = symbols.canonical_ref_for(*referenced);
if let Some(namespace_alias) = &symbols.get(canonical_ref).namespace_alias {
    canonical_ref = namespace_alias.namespace_ref;
}
depended_symbols.insert(canonical_ref);

Occurrences:

  1. Lines 237-241 — for SymbolOrMemberExprRef::Symbol references
  2. Lines 248-253 — for SymbolOrMemberExprRef::MemberExpr resolved references
  3. Lines 278-283 — for entry module resolved exports
  4. (potentially more in surrounding code)

Each occurrence performs 2 hash lookups per symbol reference: one for canonical_ref_for() and one for get() to check namespace_alias. This is called for every symbol in every statement in every module in every chunk.

Metadata

Metadata

Assignees

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions