Skip to content

perf(source-map): avoid temporary value reconstruction - #111

Merged
luojiyin1987 merged 1 commit into
masterfrom
perf/avoid-temp-value-reconstruction
Sep 7, 2026
Merged

luojiyin1987 merged 1 commit into
masterfrom
perf/avoid-temp-value-reconstruction

Conversation

@luojiyin1987

@luojiyin1987 luojiyin1987 commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

What

Eliminate explicitly constructed temporary strings and arrays during source-map validation.

Changes

  1. Inline code whitespace check: replace [...interior].some() spread with a charCodeAt loop — no character array allocation.

  2. Code segments validation (code-segments.ts): add equalRange() — a direct charCodeAt comparator that validates each span against value without creating any substring. Replaces md.slice() !== value.slice().

  3. URL segments validation: replace node.url.slice(...) with node.url.startsWith(output, valueOffset) — no substring per segment.

What was removed

Call site old temp allocation after
inline code [...interior] array charCodeAt loop
code segments sourceValue string + N× md.slice + N× value.slice equalRange (char-by-char)
URL segments value string + node.url.slice per segment startsWith (no substring)

Verification

  • 1961/1961 tests pass

Three changes eliminate unnecessary intermediate string and array
allocations during source-map construction:

1. Inline code whitespace check: replace [...interior].some() spread
   with a charCodeAt loop — avoids allocating an array of characters.

2. Code segments validation: verify each span incrementally against
   value.slice() instead of rebuilding the full sourceValue string.

3. URL segments validation: track valueMatch boolean instead of
   concatenating decoded parts into a rebuilt URL string.
@luojiyin1987
luojiyin1987 force-pushed the perf/avoid-temp-value-reconstruction branch from ada64ea to 8ce5fe0 Compare September 7, 2026 04:11
@luojiyin1987
luojiyin1987 merged commit e6c9fdd into master Sep 7, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant