Skip to content

Add zero-copy shared strings and deterministic allocation gates - #144

Merged
mxsm merged 1 commit into
mainfrom
mxsm/zero-copy-allocation-gates
Aug 12, 2026
Merged

Add zero-copy shared strings and deterministic allocation gates#144
mxsm merged 1 commit into
mainfrom
mxsm/zero-copy-allocation-gates

Conversation

@mxsm

@mxsm mxsm commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • add ownership-preserving Arc<str> conversion for long shared strings
  • remove transient heap allocation from char conversion and inline-sized concatenation
  • expose reverse, clone, and fused capabilities from lines()
  • enforce deterministic allocation and layout budgets in CI, release validation, and a dedicated performance workflow
  • add fail-closed schema-v2 allocation evidence and repository contract tests

Compatibility

  • targets CheetahString 3.1.0 with Rust 1.95 MSRV
  • cargo-semver-checks passed 196 checks against origin/main; no semver update is required
  • public API changes are additive or strengthen opaque iterator capability bounds
  • no files under docs/ or docs/rocketmq-doc are included

Verification

  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test --all-features
  • no-default and optional feature test matrices
  • Rust 1.95 packaged consumer matrix
  • default/all-feature rustdoc with warnings denied; 100% public item coverage
  • Miri core/basic/bytes suites
  • all fuzz targets build on nightly
  • i686 all-feature check
  • cargo audit, actionlint, Python repository contracts, package content audit
  • direct and independent allocation evidence verification

Closes #143

Copilot AI lite review requested due to automatic review settings August 12, 2026 08:29
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 10 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

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 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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 4307801a-ada1-4cf8-bf23-e4f0b8303fac

馃摜 Commits

Reviewing files that changed from the base of the PR and between edc7830 and 271c9ad.

馃搾 Files selected for processing (20)
  • .github/workflows/ci.yaml
  • .github/workflows/performance.yml
  • .github/workflows/release.yml
  • CHANGELOG.md
  • PERFORMANCE.md
  • README.md
  • benches/shared_backing.rs
  • scripts/bench-all.ps1
  • scripts/bench-all.sh
  • scripts/tests/test_allocation_evidence.py
  • scripts/tests/test_repository_contracts.py
  • scripts/verify-allocation-evidence.py
  • src/cheetah_string/construct.rs
  • src/cheetah_string/convert.rs
  • src/cheetah_string/query.rs
  • src/cheetah_string/traits.rs
  • src/lib.rs
  • tests/allocation_contract.rs
  • tests/api_extensions.rs
  • tests/basic.rs

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.

@mxsm
mxsm merged commit b33dbb2 into main Aug 12, 2026
16 checks passed
@mxsm
mxsm deleted the mxsm/zero-copy-allocation-gates branch August 12, 2026 08: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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

This PR adds zero-allocation adoption for long Arc<str> inputs, removes transient allocations from char conversion and inline-sized concatenation, expands lines() iterator capabilities, and introduces deterministic allocation/layout gating via tests, benchmarks, scripts, and CI workflows.

Changes:

  • Added CheetahString::from_arc_str and From<Arc<str>>, with tests and allocation evidence enforcing pointer reuse for long strings.
  • Implemented allocation-free From<char> and inline-sized concatenation fast paths, with benchmark evidence + contract tests.
  • Added fail-closed allocation evidence verification and wired deterministic performance gates into CI/release/performance workflows.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/basic.rs Adds functional tests for Arc<str> adoption behavior (pointer reuse for long, inline canonicalization for short).
tests/api_extensions.rs Adds compile-time/runtime test asserting lines() exposes DoubleEndedIterator + Clone + FusedIterator.
tests/allocation_contract.rs Extends deterministic allocation contract tests for Arc<str>, char, concatenation, and freeze-cost scenarios.
src/lib.rs Updates crate-level docs to describe Arc<str> adoption via from_arc_str.
src/cheetah_string/traits.rs Adds concatenate helper and uses it for Add<&str> / Add<String> to avoid allocations for inline-sized results.
src/cheetah_string/query.rs Strengthens lines() return bounds to expose reverse/clone/fused guarantees.
src/cheetah_string/convert.rs Adds From<Arc<str>> and makes From<char> allocation-free via UTF-8 stack buffer.
src/cheetah_string/construct.rs Introduces from_arc_str constructor and clarifies from_string shrink/copy behavior in comments.
scripts/verify-allocation-evidence.py Adds a fail-closed verifier for schema-v2 SHARED_BACKING_EVIDENCE output.
scripts/tests/test_repository_contracts.py Extends repo-contract checks to ensure CI/performance workflows include allocation evidence gates.
scripts/tests/test_allocation_evidence.py Adds unit tests for the allocation evidence verifier (validation, parsing, UTF-16 log support).
scripts/bench-all.sh Bumps capture/bench schema versions, expands contract manifest fields, and verifies evidence post-bench.
scripts/bench-all.ps1 Mirrors bench-all.sh schema/version updates and adds evidence verification on Windows.
benches/shared_backing.rs Extends benchmark to emit schema-v2 allocation evidence for CheetahString and adds inline fast-path benchmarks.
README.md Updates design contract table and examples to document Arc<str> adoption and reverse lines().
PERFORMANCE.md Adds documentation describing deterministic performance gates and how to reproduce them locally.
CHANGELOG.md Documents new API/behavior: from_arc_str, From<char> and concat fast paths, and lines() capability bounds.
.github/workflows/release.yml Adds allocation and layout contract checks to the release workflow.
.github/workflows/performance.yml Adds scheduled/PR performance-contract workflow running allocation + layout contracts and evidence verification.
.github/workflows/ci.yaml Adds a CI job to run allocation contracts and shared-backing evidence verification on PRs.

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +103 to +113
let (count, bytes, ()) = measure(|| {
for scalar in 0..=char::MAX as u32 {
if let Some(character) = char::from_u32(scalar) {
let value = CheetahString::from(black_box(character));
let mut encoded = [0; 4];
assert_eq!(value.as_str(), character.encode_utf8(&mut encoded));
black_box(value);
}
}
});
assert_eq!((count, bytes), (0, 0), "every Unicode scalar is inline");
Comment thread .github/workflows/ci.yaml
Comment on lines +109 to +130
performance-contracts:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- name: Set up stable Rust
uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c
with:
toolchain: stable

- name: Verify allocation contracts
run: cargo test --test allocation_contract --all-features -- --test-threads=1

- name: Capture shared-backing evidence
shell: bash
run: |
cargo bench --bench shared_backing -- __allocation_evidence_only__ --noplot 2>&1 |
tee target/allocation-evidence.log

- name: Verify shared-backing evidence
run: python scripts/verify-allocation-evidence.py target/allocation-evidence.log
Comment thread .github/workflows/ci.yaml
Comment on lines +109 to +130
performance-contracts:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4

- name: Set up stable Rust
uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c
with:
toolchain: stable

- name: Verify allocation contracts
run: cargo test --test allocation_contract --all-features -- --test-threads=1

- name: Capture shared-backing evidence
shell: bash
run: |
cargo bench --bench shared_backing -- __allocation_evidence_only__ --noplot 2>&1 |
tee target/allocation-evidence.log

- name: Verify shared-backing evidence
run: python scripts/verify-allocation-evidence.py target/allocation-evidence.log
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.

Add zero-copy shared strings and deterministic allocation gates

2 participants