Skip to content

perf(source-map): avoid quadratic indented-code suffix search - #118

Merged
luojiyin1987 merged 2 commits into
masterfrom
perf/avoid-quadratic-indented-code-search
Sep 24, 2026
Merged

luojiyin1987 merged 2 commits into
masterfrom
perf/avoid-quadratic-indented-code-search

Conversation

@luojiyin1987

@luojiyin1987 luojiyin1987 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Calculate the indented-code suffix start from the value length.
  • Validate the whitespace prefix and value with linear scans.
  • Remove repeated string slices from the fallback path.
  • Add fallback benchmarks for 1, 16, 64, and 256 KiB prefixes.
  • Check 64 to 256 KiB growth during the benchmark smoke run.

Performance

Batch measurements compared this branch with its parent commit.

Prefix Before After Speedup
16 KiB 0.293 ms 0.213 ms 1.38x
64 KiB 0.919 ms 0.571 ms 1.61x
256 KiB 3.437 ms 2.240 ms 1.53x

Large-prefix latency falls by approximately 35% to 40%.

The smoke benchmark measured 4.06x time growth for a 4x input increase.
This result matches linear growth.

The old algorithm has a potential O(n²) cost when string slices require copying.
The new algorithm has O(n) cost and does not create temporary suffix strings.
Current V8 versions optimize string slices, so their measured speedup is smaller.

Tests

  • pnpm test
  • pnpm run build
  • node scripts/bench-source-map.mjs --smoke

Closes #117.

Calculate the suffix start once. Scan the whitespace prefix and value once.

Add a fallback benchmark with an input growth check.

Closes #117.
Document the literal-suffix invariant. Give the benchmark fixture a precise name.
@luojiyin1987
luojiyin1987 merged commit d8721f1 into master Sep 24, 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.

perf(source-map): avoid quadratic indented-code suffix search

1 participant