Add zero-copy shared strings and deterministic allocation gates - #144
Conversation
|
Warning Review limit reached
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 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: defaults Review profile: CHILL Plan: Pro Plus Run ID: 馃搾 Files selected for processing (20)
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
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_strandFrom<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.
| 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"); |
| 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 |
| 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 |
Summary
Arc<str>conversion for long shared stringscharconversion and inline-sized concatenationlines()Compatibility
cargo-semver-checkspassed 196 checks againstorigin/main; no semver update is requireddocs/ordocs/rocketmq-docare includedVerification
cargo fmt --all -- --checkcargo clippy --all-targets --all-features -- -D warningscargo test --all-featuresCloses #143