Enable SIMD optimizations by default with auto-detection #982
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR enables SIMD (Single Instruction, Multiple Data) optimizations automatically based on CPU capabilities, providing performance improvements for JSON string parsing without requiring manual configuration.
Previously, users had to pass
--with-sse42during gem installation to enable SIMD. Now it's enabled by default and automatically detects the best instruction set for the CPU.Performance Improvements
Benchmarked on:
Results (50,000 iterations):
Key Win: Best improvements on strings with escape sequences (most common real-world scenario).
Changes
1. Simplified extconf.rb (4 lines)
Before: Required
gem install oj -- --with-sse42After: Just
gem install oj- SIMD enabled automatically ✨2. Enhanced simd.h
HAVE_SIMD_SSE4_2,HAVE_SIMD_SSE2,HAVE_SIMD_NEON#ifdefbased conditional compilation3. Optimized SIMD String Scanner (parse.c)
SSE4.2 implementation (modern x86_64):
__builtin_prefetch()__builtin_expect()SSE2 fallback (older x86_64):
Testing
✅ All tests pass: 445 runs, 986 assertions, 0 failures, 0 errors
✅ Clean builds verified
✅ Proper baseline comparisons done
Breaking Changes
None. This is a pure improvement that maintains full backward compatibility.
Benefits
Development Process
This PR was developed with Claude Code AI, which assisted with:
Related Issues
Addresses user requests for automatic SIMD enablement and improved default performance.
🤖 Built with Claude Code
Co-Authored-By: Claude [email protected]