oxc-project
json-strip-comments
BlogDocsChangelog

perf: optimize state machine with Top state fast path

#81Closed
Comparing
perf/optimize-top-state
(
622e3bd
) with
main
(
0e75e90
)
CodSpeed Performance Gauge
-3%
Regressions
1
Untouched
3

Benchmarks

Failed

minimal_comments
benches/strip.rs::strip::bench
Regression
CodSpeed Performance Gauge
-3%
2.5 µs2.5 µs

Passed

large_with_comments
benches/strip.rs::strip::bench
CodSpeed Performance Gauge
0%
58.2 µs58.2 µs
tsconfig
benches/strip.rs::strip::bench
CodSpeed Performance Gauge
0%
19.1 µs19.2 µs
no_comments
benches/strip.rs::strip::bench
CodSpeed Performance Gauge
-1%
3.8 µs3.9 µs

Commits

Click on a commit to change the comparison range
Base
main
0e75e90
-3.44%
perf: optimize state machine with Top state fast path Restructured the main state machine loop to check for the Top state first using a simple equality check instead of a match statement. Since Top is the most common state when processing JSON, this optimization improves branch prediction and reduces comparisons. Performance improvements: - minimal_comments: ~14% faster (122ns → 106ns) - large_with_comments: ~16% faster (12.2µs → 10.4µs) - no_comments: ~3% faster (482ns → 472ns) - tsconfig: ~1% faster The optimization works by: 1. Checking `if *state == Top` first (branch-prediction friendly) 2. Handling less common states in the else branch 3. Reducing pattern matching overhead for the common case 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
622e3bd
21 days ago
by Boshen
© 2025 CodSpeed Technology
Home Terms Privacy Docs