Enh: Reuse mutation fast paths#119
Conversation
|
Warning Review limit reached
More reviews will be available in 52 minutes and 59 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?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 credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. 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, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (20)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
c014d4c to
f676562
Compare
There was a problem hiding this comment.
Pull request overview
This PR primarily optimizes CheetahString mutation/concatenation paths by reusing the existing push_str logic in Add/AddAssign and adding fast returns for empty inputs, while expanding the project’s performance tooling (tests/benches) and CI/release automation. It also introduces a new memchr/memmem-based substring search implementation (and a reusable CheetahFinder) plus API changes around fallible UTF-8-checked byte conversions.
Changes:
- Rework mutation fast paths: reuse
push_str_internalforAdd/AddAssign, add empty-input fast returns, and add pointer/capacity preservation tests + mutation benchmark. - Add new substring search module (
memchr/memmem) and exposeCheetahFinder; update docs/README accordingly. - Update packaging/automation: new benches, benchmark scripts/artifact layout, multi-OS CI with layout artifacts, and a new release workflow; also tighten UTF-8 construction APIs (move some constructors to
TryFromand deprecate unchecked safe constructors).
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
Cargo.toml |
Bumps crate version, adds memchr, makes bytes optional, and registers new benches. |
src/cheetah_string.rs |
Mutation fast paths (empty fast returns, Add/AddAssign reuse), plus fallible UTF-8 byte conversion API changes and deprecations. |
src/search.rs |
New memchr/memmem-based byte substring search + CheetahFinder. |
src/lib.rs |
Wires in search module and re-exports CheetahFinder; updates crate-level docs. |
src/serde.rs |
Simplifies serde to serialize via as_str() and uses checked byte conversions on deserialize. |
src/simd.rs |
Marks now-unused SIMD substring-search helpers as dead-code allowed. |
tests/search.rs |
Adds tests validating find/rfind/contains semantics and CheetahFinder behavior. |
tests/mutation.rs |
Adds mutation tests for pointer reuse and reserve/add fast paths. |
tests/layout_snapshot.rs |
Adds a layout snapshot test that writes a JSON artifact under target/. |
tests/basic.rs |
Updates tests to use fallible try_from_* constructors and adds TryFrom trait coverage. |
benches/mutation.rs |
New Criterion bench for push/add/reserve mutation paths. |
benches/pattern.rs |
New Criterion bench for substring search and reusable finder behavior. |
benches/layout.rs |
New bench that emits a layout JSON artifact for benchmarking builds. |
benches/comprehensive.rs |
Updates bench to use try_from_vec instead of infallible byte conversion. |
scripts/bench-all.sh |
Adds a helper script to run and capture multiple benches/tests into bench-results/. |
scripts/bench-all.ps1 |
PowerShell equivalent for running and capturing benchmark outputs. |
bench-results/README.md |
Documents intended benchmark artifact layout and metadata expectations. |
README.md |
Updates README for new version and default search implementation wording. |
.github/workflows/ci.yaml |
Expands CI to a multi-OS matrix and uploads layout artifacts. |
.github/workflows/release.yml |
Adds a release workflow for tag-based and manual dispatch publishing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| [dependencies] | ||
| bytes = "1.10.0" | ||
| bytes = { version = "1.10.0", optional = true, default-features = false } | ||
| memchr = { version = "2", default-features = false } | ||
| serde = { version = "1.0", optional = true, default-features = false, features = ["alloc"] } |
| impl<'a> TryFrom<&'a [u8]> for CheetahString { | ||
| type Error = Utf8Error; | ||
|
|
||
| #[inline] | ||
| fn from(b: &[u8]) -> Self { | ||
| // SAFETY: This is unsafe and may cause UB if bytes are not valid UTF-8. | ||
| // This will be deprecated in favor of try_from_bytes in the next version. | ||
| CheetahString::from_slice(unsafe { str::from_utf8_unchecked(b) }) | ||
| fn try_from(b: &'a [u8]) -> Result<Self, Self::Error> { |
| - name: Create tag for manual release | ||
| if: github.event_name == 'workflow_dispatch' | ||
| shell: bash | ||
| run: | | ||
| TAG="${{ steps.version.outputs.tag }}" |
| #!/usr/bin/env sh | ||
| set -eu |
|
|
||
| mod cheetah_string; | ||
| mod error; | ||
| mod search; |
| /// Find the first occurrence of needle in haystack using SIMD when available | ||
| #[allow(dead_code)] | ||
| #[inline] | ||
| pub(crate) fn find_bytes(haystack: &[u8], needle: &[u8]) -> Option<usize> { |
Implements the push_str/Add/reserve fast-path stage.
Scope:
push_strinAddimplementations.Verification completed locally:
cargo test --test mutation --all-featurescargo bench --bench mutation --no-runCloses #111.