oxc-project
json-strip-comments
BlogDocsChangelog

perf: optimize state machine for comment stripping

#79Merged
Comparing
perf/optimize-state-machine
(
b187caa
) with
main
(
bd142bb
)
CodSpeed Performance Gauge
+10%
Improvements
2
Untouched
2

Benchmarks

Improved

tsconfig
benches/strip.rs::strip::bench
CodSpeed Performance Gauge
+10%
21.5 µs19.6 µs
large_with_comments
benches/strip.rs::strip::bench
CodSpeed Performance Gauge
+6%
66.1 µs62.1 µs

Passed

no_comments
benches/strip.rs::strip::bench
CodSpeed Performance Gauge
+2%
4.1 µs4 µs
minimal_comments
benches/strip.rs::strip::bench
CodSpeed Performance Gauge
+2%
2.6 µs2.6 µs

Commits

Click on a commit to change the comparison range
Base
main
bd142bb
+9.75%
perf: optimize state machine for comment stripping Implemented several performance optimizations to improve the efficiency of the comment stripping state machine: - Added #[repr(u8)] to State enum for more compact memory representation - Simplified state machine logic by removing redundant branching in main loop - Added #[inline(always)] annotations to force inlining of hot path functions - Cached buffer length to avoid repeated len() calls - Optimized slice access patterns to reduce re-computation Benchmark results show ~5% improvement for minimal_comments scenario (from 121ns to 117ns), with mixed results for other scenarios staying within noise threshold. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
b187caa
22 days ago
by Boshen
© 2025 CodSpeed Technology
Home Terms Privacy Docs