⚡ Find the single-quoted scalar end with SIMD memchr#228
Conversation
|
Warning Review limit reached
Next review available in: 50 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughChangesA Sequence Diagram(s)Not applicable; the change is a scanning algorithm modification without cross-component interaction changes. Related Issues: None referenced in the provided information. Related PRs: None referenced in the provided information. Suggested labels: performance, dependencies, scanner Suggested reviewers: frenck Poem 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Optimizes the YAML scanner’s single-quoted scalar fast path by replacing the per-byte stop-byte loop with a SIMD-accelerated memchr3 search, improving throughput on long single-quoted scalars while preserving identical parse results.
Changes:
- Replace the single-quoted scalar run scan with
memchr::memchr3and adjust column tracking to handle non-ASCII runs accurately. - Promote
memchrto a direct Rust dependency (already present transitively) and record it in the lockfile.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/scanner/reader.rs | Reworks take_single_quoted_run to locate stop bytes via memchr3 and updates column advancement logic accordingly. |
| Cargo.toml | Adds memchr = "2" as a direct dependency with rationale comments. |
| Cargo.lock | Records memchr as a direct dependency of the crate. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #228 +/- ##
==========================================
- Coverage 92.55% 92.52% -0.03%
==========================================
Files 41 41
Lines 12782 12837 +55
==========================================
+ Hits 11830 11878 +48
- Misses 952 959 +7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Breaking change
None. Pure internal optimization; parse results are byte-for-byte identical.
Proposed change
Follow-up to the quoted-scalar work (#224, #225, #226). The single-quoted content scan introduced in #226 walked the run one byte at a time, testing each byte against the closing quote, the line breaks, and the non-ASCII range.
This replaces that loop with a SIMD
memchr3search for the next stop byte (',\n,\r), so a long scalar (a description, an embedded script, a base64 blob) is skipped in a handful of vector loads instead of a comparison per byte. Column tracking stays exact:columnis per character, so it advances by the run's byte length when the run is pure ASCII (the common case, checked with a SIMDis_ascii) and by an exact character count only when the run carries multi-byte content.memchrwas already a transitive dependency (viaregex), so promoting it to a direct dependency adds no build cost.Single-quoted has exactly three stop bytes, a natural fit for
memchr3; double-quoted has four (it also stops at\), so it keeps its byte loop.Measured with callgrind on a multi-document single-quoted corpus: ~3% fewer instructions overall (its scalars are mostly short). The win scales with scalar length: on a stream of long single-quoted strings the scan is several times faster, since the per-byte loop is replaced by vector search. Behavior is unchanged: the full suite, the YAML compliance suite, all Rust unit tests, and round-trip plus parse fuzzing pass with no differences.
Type of change
Additional information
Checklist
uv run pytestpasses locally. A pull request cannot be merged unless CI is green.uv run ruff check .anduv run ruff format --check .pass.cargo fmt --checkandcargo clippy --all-targets -- -D warningspass.If the change is user-facing:
docs/is added or updated, anddocs/verify_examples.pystill passes.