-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels