Skip to content

Conversation

Boshen
Copy link
Member

@Boshen Boshen commented Sep 15, 2025

Summary

  • Optimized the comment stripping state machine for better performance
  • Achieved ~5% improvement in minimal_comments benchmark scenario

Changes

  • Added #[repr(u8)] to State enum for more compact memory representation
  • Simplified state machine logic by removing redundant branching in the 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

Test Results

All tests pass successfully:

test result: ok. 13 passed; 0 failed; 0 ignored

Benchmark Results

  • minimal_comments: ~5% improvement (121ns → 117ns)
  • no_comments: Within noise threshold
  • tsconfig: Within noise threshold
  • large_with_comments: Within noise threshold

The optimizations primarily benefit scenarios with minimal comments where state machine transitions are simpler.

🤖 Generated with Claude Code

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 <[email protected]>
Copy link

codspeed-hq bot commented Sep 15, 2025

CodSpeed Performance Report

Merging #79 will improve performances by 9.75%

Comparing perf/optimize-state-machine (b187caa) with main (bd142bb)

Summary

⚡ 2 improvements
✅ 2 untouched

Benchmarks breakdown

Benchmark BASE HEAD Change
large_with_comments 66.1 µs 62.1 µs +6.4%
tsconfig 21.5 µs 19.6 µs +9.75%

@Boshen Boshen merged commit 931408c into main Sep 15, 2025
7 checks passed
@Boshen Boshen deleted the perf/optimize-state-machine branch September 15, 2025 06:07
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