Skip to content

perf(swc_ts_fast_strip): add ASCII fast path for strip-only replacement loop #11658

@kdy1

Description

@kdy1

Summary

The strip-only replacement pass decodes replacement ranges as UTF-8 chars one-by-one, with no ASCII fast path.

Evidence

  • Replacement loop: crates/swc_ts_fast_strip/src/lib.rs:342-387.
  • For every replacement span, it iterates char_indices() and runs a large whitespace/newline match for each character.

Why this is a performance risk

Most TypeScript source is ASCII-heavy. Full UTF-8 char decoding and large match branching on every character can dominate strip-only runtime for heavily annotated files.

Suggested direction

  • Add an ASCII fast path (byte-wise) for spans that are ASCII.
  • Keep the current Unicode-safe slow path for non-ASCII spans.
  • Consider normalizing/merging adjacent replacement ranges before mutation to reduce loop overhead.

Benchmark idea

Profile strip-only runs on large ASCII-dominant TS files (and mixed Unicode fixtures) to verify speedup without semantic regressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions