Skip to content

Reduce CheetahString to a provenance-safe 24-byte layout - #149

Merged
mxsm merged 1 commit into
mainfrom
mxsm/provenance-safe-24-byte-layout
Aug 12, 2026
Merged

Reduce CheetahString to a provenance-safe 24-byte layout#149
mxsm merged 1 commit into
mainfrom
mxsm/provenance-safe-24-byte-layout

Conversation

@mxsm

@mxsm mxsm commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • replace the unrestricted inline length byte with a constrained 0-through-23 Rust enum
  • use the enum's invalid discriminants as compiler layout niches for the stable storage enum and Option
  • reduce CheetahString and Option<CheetahString> to 24 bytes while preserving the 23-byte SSO boundary
  • retain ordinary &'static str and Arc<str> pointers without integer conversion, reconstruction, unions, or manual drop logic
  • enforce 32-bit and 64-bit layout plus downstream vector/map-entry slot footprints
  • upgrade allocation evidence to schema v3 and add a dedicated i686 CI layout job

Compatibility

  • targets CheetahString 3.1.0 with Rust 1.95 MSRV
  • preserves all public behavior, storage precedence, allocation budgets, and shared-clone semantics
  • cargo-semver-checks passed 196 checks against origin/main; no semver update is required
  • no files under docs/ or docs/rocketmq-doc are included

Evidence

  • 64-bit: CheetahString 24 bytes, Option<CheetahString> 24 bytes, (CheetahString, u64) 32 bytes
  • i686: CheetahString 24 bytes and Option<CheetahString> 24 bytes, executed rather than compile-only
  • 10,000 vector slots: 240,000 bytes, saving 80,000 bytes versus the prior contract
  • schema-v3 allocation evidence retains all zero-copy and allocation budgets

Verification

  • format, clippy, all-feature and no-default test matrices
  • Rust 1.95 layout test and packaged consumer matrix
  • stable/nightly rustdoc with warnings denied and 100% public item coverage
  • Miri core/basic/bytes suites, including every compact Option storage mode
  • all fuzz targets build on nightly
  • cargo audit, actionlint, Python repository contracts, package content audit
  • cargo-semver-checks minor-release comparison

Closes #145

Summary by CodeRabbit

  • Performance

    • Reduced CheetahString and Option<CheetahString> memory usage to 24 bytes while preserving 23-byte inline capacity.
    • Added downstream memory and vector storage measurements to allocation reporting.
  • Documentation

    • Documented stable memory layouts, storage behavior, performance impacts, safety considerations, and ABI caveats.
  • Tests

    • Added layout coverage across 32-bit and 64-bit platforms, including Windows.
    • Added regression checks for allocation limits and storage-mode round trips.

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

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 99aaba51-3f22-4390-8375-b92b79c4d755

📥 Commits

Reviewing files that changed from the base of the PR and between b33dbb2 and 311b8fb.

📒 Files selected for processing (15)
  • .github/workflows/ci.yaml
  • CHANGELOG.md
  • LAYOUT.md
  • PERFORMANCE.md
  • README.md
  • SAFETY.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/inline.rs
  • tests/basic.rs
  • tests/layout_snapshot.rs

📝 Walkthrough

Walkthrough

The PR replaces the inline length byte with a constrained enum to enable a provenance-safe 24-byte representation. It adds layout and allocation contract checks, Windows 32-bit CI coverage, and documentation for the representation and verification requirements.

Changes

Compact CheetahString layout

Layer / File(s) Summary
Constrained inline representation
src/inline.rs, tests/basic.rs
InlineLength represents lengths from 0 to 23. InlineStr uses the enum for validation and access. Tests cover boundaries, layout, and Option<CheetahString> storage modes.
Layout snapshots and CI enforcement
tests/layout_snapshot.rs, scripts/tests/test_repository_contracts.py, .github/workflows/ci.yaml
Layout tests require 24-byte CheetahString and Option<CheetahString> values on supported targets. CI adds the Windows i686 snapshot job.
Allocation evidence validation
benches/shared_backing.rs, scripts/bench-all.*, scripts/verify-allocation-evidence.py, scripts/tests/test_allocation_evidence.py
Allocation evidence changes to schema version 3 and records downstream vector and map-entry footprints. Validation rejects missing or mismatched metrics.
Layout and safety contract
LAYOUT.md, PERFORMANCE.md, README.md, SAFETY.md, CHANGELOG.md
Documentation describes the 24-byte representation, 23-byte inline capacity, provenance constraints, footprint measurements, and verification commands.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related issues

  • Issue 143: Related to CheetahString storage, layout contracts, and benchmark evidence.

Possibly related PRs

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mxsm/provenance-safe-24-byte-layout

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 74c4293 into main Aug 12, 2026
16 of 17 checks passed
@mxsm
mxsm deleted the mxsm/provenance-safe-24-byte-layout branch August 12, 2026 08:42

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.

Reduce CheetahString’s footprint to a provenance-safe 24-byte layout using enum niches, and extend CI/tests/docs/evidence to enforce the new stable layout across 32-bit and 64-bit targets.

Changes:

  • Introduce a constrained InlineLength enum to enable niche-based 24-byte layouts for CheetahString and Option<CheetahString>.
  • Expand layout/allocation evidence (schema v3) and add downstream container slot checks.
  • Add 32-bit (i686 Windows MSVC) CI coverage and strengthen tests/docs around the stable layout contract.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/layout_snapshot.rs Updates layout assertions and snapshots for 24-byte CheetahString and tuple slot footprints.
tests/basic.rs Adds a regression test ensuring Option<CheetahString> round-trips across all storage modes.
src/inline.rs Replaces u8 length with constrained InlineLength enum and adds unit tests for layout/coverage.
scripts/verify-allocation-evidence.py Bumps evidence schema to v3 and validates new downstream slot footprint fields.
scripts/tests/test_repository_contracts.py Adds contract checks preventing pointer-integerization and enforces i686 layout CI command presence.
scripts/tests/test_allocation_evidence.py Updates evidence schema/version and adds a regression test for downstream slot footprint.
scripts/bench-all.sh Updates bench schema IDs and contract JSON to schema v3 + new size/slot fields.
scripts/bench-all.ps1 Same as bench-all.sh for PowerShell environments.
benches/shared_backing.rs Emits schema v3 evidence, including downstream slot footprint metrics.
SAFETY.md Documents the niche-based 24-byte layout and its provenance/pointer-safety story.
README.md Documents the 24-byte sizes and downstream slot savings, linking to the stable layout doc.
PERFORMANCE.md Updates performance contracts to include 24-byte layouts and downstream slot footprints; schema v3 wording.
LAYOUT.md Adds a new stable layout contract document describing the niche strategy and enforced sizes.
CHANGELOG.md Notes the size reduction and provenance-safe niche approach.
.github/workflows/ci.yaml Adds a dedicated i686 Windows job to enforce the 32-bit compact layout.

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

Comment thread CHANGELOG.md
Comment on lines +35 to +38
- Reduced `CheetahString` and `Option<CheetahString>` from 32 to 24 bytes on
64-bit targets while preserving the 23-byte inline capacity. The stable
representation uses constrained Rust enum discriminants as layout niches and
does not encode pointers as integers.
Comment on lines +53 to +63
def test_compact_layout_does_not_integerize_or_reconstruct_pointers(self) -> None:
source = read("src/inline.rs")
self.assertIn("enum InlineLength", source)
self.assertEqual(source.count("unsafe {"), 2)
for forbidden in (
"from_raw_parts",
"transmute",
"expose_provenance",
"with_exposed_provenance",
):
self.assertNotIn(forbidden, source)
Comment thread src/inline.rs
Comment on lines +41 to +68
const fn new(len: usize) -> Option<Self> {
match len {
0 => Some(Self::L0),
1 => Some(Self::L1),
2 => Some(Self::L2),
3 => Some(Self::L3),
4 => Some(Self::L4),
5 => Some(Self::L5),
6 => Some(Self::L6),
7 => Some(Self::L7),
8 => Some(Self::L8),
9 => Some(Self::L9),
10 => Some(Self::L10),
11 => Some(Self::L11),
12 => Some(Self::L12),
13 => Some(Self::L13),
14 => Some(Self::L14),
15 => Some(Self::L15),
16 => Some(Self::L16),
17 => Some(Self::L17),
18 => Some(Self::L18),
19 => Some(Self::L19),
20 => Some(Self::L20),
21 => Some(Self::L21),
22 => Some(Self::L22),
23 => Some(Self::L23),
_ => None,
}
Comment on lines 8 to 13
ROOT = Path(__file__).resolve().parents[2]
WORKFLOWS = ROOT / ".github" / "workflows"


def read(path: str) -> str:
return (ROOT / path).read_text(encoding="utf-8")
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.

Reduce CheetahString to a provenance-safe 24-byte layout

2 participants