-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Description
Summary
TsStrip performs many token-position lookups via binary search, which likely adds avoidable log-factor overhead.
Evidence
- Core lookup helpers use binary search every time:
crates/swc_ts_fast_strip/src/lib.rs:627-633(get_next_token_index)crates/swc_ts_fast_strip/src/lib.rs:639-644(get_prev_token_index)
- These lookups are called from many visitor paths (
visit_arrow_expr,visit_class_prop,visit_params,visit_getter_prop, etc.).
Why this is a performance risk
TsStrip does a lot of local token queries while walking the AST. Repeated binary_search_by_key calls can add up to O(k log n) token-lookup cost (k = number of strip/fix operations).
Suggested direction
- Introduce an index cursor in
TsStripand advance it as traversal moves forward in source order (amortized nearO(1)local lookups). - Alternatively, precompute a compact position->token-index table for the span boundaries used by stripping logic.
Benchmark idea
Use the existing typescript/fast-strip benchmark and compare time spent in token lookup helpers before/after cursorization.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels