Feat: Add layout and benchmark artifacts#117
Conversation
|
Warning Review limit reached
More reviews will be available in 53 minutes and 2 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 (15)
✨ 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 |
There was a problem hiding this comment.
Pull request overview
This PR introduces a repeatable “layout snapshot” + benchmark-artifact capture path (tests/benches/scripts) and wires layout artifact upload into CI, while also tightening byte-based construction/serde behavior for CheetahString and bumping the crate version to 1.1.0.
Changes:
- Add layout snapshot generation (
tests/layout_snapshot.rs) and a bench-mode layout artifact generator (benches/layout.rs). - Add benchmark artifact conventions + runner scripts (
bench-results/README.md,scripts/bench-all.*) and upload layout artifacts from CI. - Refactor
CheetahStringbyte conversions to be UTF-8 checked (TryFrom+ new explicit unsafe constructors), and simplify serde serialization.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/layout_snapshot.rs | Generates a JSON layout snapshot artifact during tests. |
| tests/basic.rs | Updates tests to use fallible UTF-8-checked constructors; adds TryFrom trait coverage. |
| src/serde.rs | Serializes consistently via as_str(); deserializes bytes with UTF-8 validation. |
| src/lib.rs | Updates docs to reference v1.1.0 (SIMD example). |
| src/cheetah_string.rs | Introduces checked byte conversions + explicit unsafe constructors; deprecates some constructors. |
| scripts/bench-all.sh | Adds Unix bench/layout capture script writing outputs to bench-results/. |
| scripts/bench-all.ps1 | Adds PowerShell bench/layout capture script writing outputs to bench-results/. |
| README.md | Updates dependency examples to v1.1.0. |
| Cargo.toml | Bumps version to 1.1.0, makes bytes optional, and adds layout bench target. |
| benches/layout.rs | Adds a bench artifact generator for layout snapshot data. |
| benches/comprehensive.rs | Updates benchmark cases to use the new checked constructor. |
| bench-results/README.md | Documents artifact directory layout and recommended metadata. |
| .github/workflows/release.yml | Adds a release workflow (tag/publish/release). |
| .github/workflows/ci.yaml | Runs CI on OS/toolchain matrix and uploads layout artifacts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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> { | ||
| CheetahString::try_from_bytes(b) | ||
| } |
| impl TryFrom<Vec<u8>> for CheetahString { | ||
| type Error = Utf8Error; | ||
|
|
||
| #[inline] | ||
| fn from(v: Vec<u8>) -> Self { | ||
| // SAFETY: This constructor does not validate UTF-8 and may cause UB | ||
| // if the bytes are later observed as a string. | ||
| CheetahString::from_vec(v) | ||
| fn try_from(v: Vec<u8>) -> Result<Self, Self::Error> { | ||
| CheetahString::try_from_vec(v) | ||
| } |
| #[cfg(feature = "bytes")] | ||
| impl From<bytes::Bytes> for CheetahString { | ||
| impl TryFrom<bytes::Bytes> for CheetahString { | ||
| type Error = Utf8Error; | ||
|
|
||
| #[inline] | ||
| fn from(b: bytes::Bytes) -> Self { | ||
| CheetahString::from_bytes(b) | ||
| fn try_from(b: bytes::Bytes) -> Result<Self, Self::Error> { | ||
| CheetahString::try_from_bytes_buf(b) | ||
| } | ||
| } |
| #!/usr/bin/env sh | ||
| set -eu | ||
|
|
||
| VERSION="${1:-current}" | ||
| RESULT_DIR="bench-results/${VERSION}" | ||
|
|
||
| mkdir -p "$RESULT_DIR" | ||
|
|
||
| cargo test layout_snapshot --all-features -- --nocapture | tee "$RESULT_DIR/layout-test.txt" | ||
| cargo bench --bench layout | tee "$RESULT_DIR/layout-bench.txt" | ||
| cargo bench --bench comprehensive | tee "$RESULT_DIR/comprehensive.txt" | ||
| cargo bench --bench simd --features simd | tee "$RESULT_DIR/simd.txt" |
| $Version = if ($args.Count -gt 0) { $args[0] } else { "current" } | ||
| $ResultDir = Join-Path "bench-results" $Version | ||
|
|
||
| New-Item -ItemType Directory -Force -Path $ResultDir | Out-Null | ||
|
|
||
| cargo test layout_snapshot --all-features -- --nocapture | | ||
| Tee-Object -FilePath (Join-Path $ResultDir "layout-test.txt") | ||
|
|
||
| cargo bench --bench layout | | ||
| Tee-Object -FilePath (Join-Path $ResultDir "layout-bench.txt") | ||
|
|
||
| cargo bench --bench comprehensive | | ||
| Tee-Object -FilePath (Join-Path $ResultDir "comprehensive.txt") | ||
|
|
||
| cargo bench --bench simd --features simd | | ||
| Tee-Object -FilePath (Join-Path $ResultDir "simd.txt") |
| let snapshot = format!( | ||
| concat!( | ||
| "{{\n", | ||
| " \"crate\":\"cheetah-string\",\n", | ||
| " \"profile\":\"test\",\n", | ||
| " \"target_arch\":\"{}\",\n", | ||
| " \"target_os\":\"{}\",\n", | ||
| " \"pointer_width\":\"{}\",\n", | ||
| " \"layouts\":[\n {}\n ]\n", | ||
| "}}\n" | ||
| ), | ||
| env::consts::ARCH, | ||
| env::consts::OS, | ||
| std::mem::size_of::<usize>() * 8, | ||
| layouts.join(",\n ") |
| fn target_dir() -> PathBuf { | ||
| env::var_os("CARGO_TARGET_DIR") | ||
| .map(PathBuf::from) | ||
| .unwrap_or_else(|| PathBuf::from("target")) | ||
| } | ||
|
|
||
| fn layout_entry<T>(name: &str) -> String { | ||
| format!( | ||
| r#"{{"type":"{}","size":{},"align":{}}}"#, | ||
| name, | ||
| size_of::<T>(), | ||
| align_of::<T>() | ||
| ) | ||
| } |
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "v*.*.*" | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: "Version to release, for example 1.1.0" | ||
| required: true | ||
| type: string |
| - name: Test | ||
| run: cargo test --verbose --all-features | ||
|
|
||
| - name: Layout snapshot | ||
| run: cargo test layout_snapshot --all-features -- --nocapture | ||
|
|
||
| - name: Upload layout artifacts | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: layout-${{ matrix.os }}-${{ matrix.rust }} | ||
| path: target/layout-artifacts | ||
| if-no-files-found: ignore |
7d8e78e to
ab3ef5c
Compare
Implements the layout snapshot and benchmark artifact stage.
Scope:
tests/layout_snapshot.rsandbenches/layout.rs.Verification completed locally:
cargo test layout_snapshot --all-features -- --nocapturecargo bench --bench layoutCloses #109.