Skip to content

perf(source-map): streamline range-query hot path - #120

Merged
luojiyin1987 merged 1 commit into
masterfrom
perf/range-query-hot-path
Sep 24, 2026
Merged

luojiyin1987 merged 1 commit into
masterfrom
perf/range-query-hot-path

Conversation

@luojiyin1987

@luojiyin1987 luojiyin1987 commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Select the value segment WeakMap from node.type.
  • Remove the per-query validation closure.
  • Split index and bounds checks while preserving error precedence.
  • Read emptyCodeOffsets only for code nodes.

Benchmark

The existing benchmark uses a text node and measures repeated range queries.
Text mappings already hit the first segment WeakMap before this change.
This case measures the validation and emptyCodeOffsets changes.
It does not measure the reduced map probes for code nodes.

A representative 256 KiB query every code unit run changed from 12.32 ms to 11.13 ms.
This result is a 9.7% reduction.
Same-process A/B runs showed approximately 10% to 25% gains for large repeated-query workloads.

Results below 2 ms changed significantly between runs due to JIT and timer noise.
This PR does not claim the observed 16 KiB result as a stable 52.9% improvement.
Single queries and small workloads will not show a material difference.
Build performance does not change.

Tests

  • pnpm test
  • pnpm run build
  • node scripts/bench-source-map.mjs
  • ESLint and TypeScript checks

Closes #119.

Select the segment map from the node type.

Validate indices and bounds without allocating a closure.

Closes #119.
@luojiyin1987
luojiyin1987 merged commit 3056baa into master Sep 24, 2026
14 checks passed
@luojiyin1987
luojiyin1987 deleted the perf/range-query-hot-path branch September 24, 2026 03:13
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): streamline the range-query hot path

1 participant