Skip to content

perf(swc_ts_fast_strip): skip comment collection in strip-only mode #11659

@kdy1

Description

@kdy1

Summary

Strip-only mode appears to collect parser comments even though comments are not used in that mode.

Evidence

  • Comments storage is always initialized: crates/swc_ts_fast_strip/src/lib.rs:246.
  • Lexer always receives Some(&comments): crates/swc_ts_fast_strip/src/lib.rs:248-253.
  • In Mode::StripOnly, output is produced by mutating the original source bytes; no comment map is consulted.

Why this is a performance risk

Comment collection adds parser-side bookkeeping and memory overhead on every strip-only call, even though the comment data is unused on that path.

Suggested direction

  • Pass None for comments when running strip-only mode.
  • Keep comment collection for transform mode where fixer/codegen paths may rely on comment metadata.

Benchmark idea

Measure strip-only throughput and allocations before/after disabling comment collection for strip-only.

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