Skip to content

perf(swc_ecma_transforms_base/rename): use FxHashMap in concurrent child aggregation #11666

@kdy1

Description

@kdy1

Summary

In the concurrent-renamer path, child rename maps are built with std::collections::HashMap and then merged into an FxHashMap.

This introduces avoidable hasher overhead and rehashing in a path explicitly chosen for large rename workloads.

Evidence

crates/swc_ecma_transforms_base/src/rename/analyzer/scope.rs:

  • Concurrent branch allocates std map per child: lines 247-259.
  • Results are flattened into to: FxHashMap<Id, V>: lines 263-264.
  • This branch is selected when parallel is true (high-cost rename cases).

Why this is a perf issue

Using std hash maps here means:

  • slower hashing during child map build (SipHash),
  • and extra hashing cost again when reinserting into FxHashMap.

For large scopes with many child bindings this adds measurable overhead to the parallel fast path.

Suggested direction

  • Use FxHashMap<Id, V> for new_map in the concurrent branch.
  • Optionally reserve capacity from child scope queue size when available.

Notes

Static-analysis report only (no benchmark attached yet).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions