Commits
Click on a commit to change the comparison rangeperf(lexer): add `#[cold]` to unicode path (#12768)
This PR refactors the lexer to use `#[cold]` functions instead of runtime branch prediction hints for better performance optimization.
## Background
Previously attempted to optimize lexer performance using the `likely_stable` crate with `likely()` and `unlikely()` hints. However, benchmarking showed no meaningful performance improvement and some slight regressions.
## Changes
Instead of runtime branch prediction hints, this approach uses `#[cold]` function attributes to move rarely executed code paths out of the hot path:
- **String handling**: Extract escape sequence processing into `save_escaped_string()`
- **Numeric parsing**: Move decimal point and BigInt suffix handling into cold functions
- **Unicode processing**: Separate Unicode character handling from ASCII fast path in `next_char()`, `next_2_chars()`, and `peek_char()`
- **Error cases**: Move irregular whitespace and invalid character handling into cold functions
## Benefits
The `#[cold]` attribute tells the compiler that these functions are rarely executed, allowing it to:
- Keep hot paths compact and well-predicted
- Move cold code out of instruction cache pressure
- Optimize register allocation for common cases
- Provide better performance than manual runtime hints
This approach achieves similar optimization goals while being more maintainable and letting the compiler make informed decisions about code layout.
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click [here](https://survey.alchemer.com/s3/8343779/Copilot-Coding-agent) to start the survey.