Skip to content

Enh: Reuse mutation fast paths#119

Merged
mxsm merged 5 commits into
mainfrom
codex/pr-006-mutation-fast-paths
Jun 20, 2026
Merged

Enh: Reuse mutation fast paths#119
mxsm merged 5 commits into
mainfrom
codex/pr-006-mutation-fast-paths

Conversation

@mxsm

@mxsm mxsm commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Implements the push_str/Add/reserve fast-path stage.

Scope:

  • Reuses push_str in Add implementations.
  • Adds empty input fast returns.
  • Adds mutation tests for pointer reuse and capacity preservation.
  • Adds mutation benchmark.

Verification completed locally:

  • cargo test --test mutation --all-features
  • cargo bench --bench mutation --no-run
  • final full verification matrix on integration branch

Closes #111.

Copilot AI review requested due to automatic review settings June 20, 2026 02:23
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@mxsm, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4fb1dfdd-6673-40f1-9dc9-d2254f25c88e

📥 Commits

Reviewing files that changed from the base of the PR and between 21aa0bf and f676562.

📒 Files selected for processing (20)
  • .github/workflows/ci.yaml
  • .github/workflows/release.yml
  • Cargo.toml
  • README.md
  • bench-results/README.md
  • benches/comprehensive.rs
  • benches/layout.rs
  • benches/mutation.rs
  • benches/pattern.rs
  • scripts/bench-all.ps1
  • scripts/bench-all.sh
  • src/cheetah_string.rs
  • src/lib.rs
  • src/search.rs
  • src/serde.rs
  • src/simd.rs
  • tests/basic.rs
  • tests/layout_snapshot.rs
  • tests/mutation.rs
  • tests/search.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/pr-006-mutation-fast-paths

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mxsm mxsm force-pushed the codex/pr-006-mutation-fast-paths branch from c014d4c to f676562 Compare June 20, 2026 02:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_internal for Add/AddAssign, add empty-input fast returns, and add pointer/capacity preservation tests + mutation benchmark.
  • Add new substring search module (memchr/memmem) and expose CheetahFinder; 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 TryFrom and 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.

Comment thread Cargo.toml
Comment on lines 17 to 20
[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"] }
Comment thread src/cheetah_string.rs
Comment on lines +50 to +54
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> {
Comment on lines +60 to +64
- name: Create tag for manual release
if: github.event_name == 'workflow_dispatch'
shell: bash
run: |
TAG="${{ steps.version.outputs.tag }}"
Comment thread scripts/bench-all.sh
Comment on lines +1 to +2
#!/usr/bin/env sh
set -eu
Comment thread src/lib.rs

mod cheetah_string;
mod error;
mod search;
Comment thread src/simd.rs
Comment on lines 90 to 93
/// 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> {
@mxsm mxsm merged commit 6cac969 into main Jun 20, 2026
7 checks passed
@mxsm mxsm deleted the codex/pr-006-mutation-fast-paths branch June 20, 2026 08:41
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.

Enh: Optimize push_str, Add, AddAssign, and reserve fast paths

2 participants