Skip to content

perf(decode): single-pass mapping parser#268

Merged
Boshen merged 2 commits intomainfrom
perf/decode-single-pass-parser
Feb 8, 2026
Merged

perf(decode): single-pass mapping parser#268
Boshen merged 2 commits intomainfrom
perf/decode-single-pass-parser

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Feb 8, 2026

Summary

  • rewrite decode_mapping in src/decode.rs from split(';')/split(',') iteration to a cursor-based single-pass byte scanner
  • remove per-segment heap allocation (Vec<i64>) and decode into a fixed [i64; 5] stack buffer
  • preserve existing decode semantics and errors while reducing parsing overhead
  • add malformed mapping coverage for bad segment size and VLQ leftovers

Key Changes

  • delimiter-driven scanner over mapping.as_bytes()
  • line and column state updates done inline while scanning
  • new parse_vlq_segment_into(mapping, &mut cursor, &mut [i64; 5]) -> Result<usize> helper

Tests

  • cargo fmt
  • cargo check --all-targets --all-features
  • cargo test
  • cargo bench --bench simple -- parse/real_large --warm-up-time 0.1 --measurement-time 0.2 --sample-size 10

Benchmark Note

Quick parse benchmark for parse/real_large improved from ~531 MiB/s to ~644 MiB/s in this environment (~21% throughput increase).

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 8, 2026

CodSpeed Performance Report

Merging this PR will degrade performance by 4.02%

Comparing perf/decode-single-pass-parser (1feefc8) with main (ee47629)

Summary

⚡ 6 improved benchmarks
❌ 3 regressed benchmarks
✅ 4 untouched benchmarks
⏩ 5 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
serialize[real_small] 4.4 µs 4.3 µs +1.94%
lookup_table[real_large] 4.4 µs 4.5 µs -1.31%
lookup_table[real_medium] 1.4 µs 1.5 µs -4.02%
from_sourcemaps 17.8 µs 17.5 µs +1.76%
parse[real_small] 13.8 µs 12.9 µs +7.03%
add_sourcemap_loop 20.4 µs 21 µs -2.87%
from_json_string_inline 16.5 µs 15.6 µs +5.48%
parse[real_medium] 17.4 µs 16.3 µs +6.98%
parse[real_large] 66.5 µs 56.9 µs +16.84%

Footnotes

  1. 5 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Boshen Boshen merged commit fcc1f26 into main Feb 8, 2026
7 checks passed
@Boshen Boshen deleted the perf/decode-single-pass-parser branch February 8, 2026 05:37
@Boshen Boshen mentioned this pull request Feb 8, 2026
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