CheetahString
CheetahString is an immutable, clone-cheap UTF-8 value for latency-sensitive
systems. It stores short text inline, keeps static text allocation-free, and
shares long dynamic text through Arc<str>. The same value contract works with
std and no_std + alloc.
Version 3.0.0-alpha.1 is the opt-in preview of the immutable architecture.
Design contract
| Storage | Condition | Construction allocation | Clone allocation |
|---|---|---|---|
| Inline | UTF-8 length ≤ 23 bytes | 0 | 0 |
| Static | &'static str |
0 | 0 |
| Shared | Other long text | 1 live backing allocation | 0 |
The representation has no mutable Owned(String) state. Construction history
therefore cannot change clone complexity. Use:
CheetahStringfor protocol text, immutable fields, and collection keys;CheetahBuilderfor append-heavy construction followed byfinish();- standard
Stringwhen mutation or spare capacity must continue; CheetahBytesfor byte semantics when the optionalbytesfeature is active.
Installation
Opt into the alpha explicitly:
[]
= "=3.0.0-alpha.1"
With optional integrations:
[]
= {
version = "=3.0.0-alpha.1",
= ["serde", "bytes"]
}
The minimum supported Rust version is 1.75.
Quick start
use ;
let inline = from;
let static_value = from_static_str;
let shared = from_string;
let cloned = shared.clone;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
let mut builder = with_capacity;
builder.push_str;
builder.push;
builder.push_str;
let route_key = builder.finish;
assert_eq!;
When mutation continues, keep the builder's String:
use CheetahBuilder;
let mut builder = with_capacity;
builder.push_str;
let mut value = builder.into_string;
value.push_str;
Search and split
Equality, prefix, and suffix checks use Rust's portable slice/str paths.
Substring search uses memchr/memmem.
Iterator capabilities are explicit:
use CheetahString;
let value = from;
let forward: = value.split_str.collect;
assert_eq!;
let csv = from;
let reverse: = csv.split_char.rev.collect;
assert_eq!;
split_str is intentionally forward-only. Unsupported reverse iteration fails
at compile time instead of panicking at runtime.
Bytes interoperability
The ownership boundary is explicit:
| Conversion | UTF-8 validation | Payload copy |
|---|---|---|
bytes::Bytes -> CheetahBytes |
No | No |
CheetahBytes -> bytes::Bytes |
No | No |
Bytes -> CheetahString::try_from |
Yes | Yes |
CheetahBytes -> CheetahString::try_from |
Yes | Yes |
Bytes -> CheetahString::try_copy_from_bytes |
Yes | Yes |
&CheetahBytes -> try_copy_to_cheetah_string |
Yes | Yes |
use Bytes;
use ;
let raw = from_static;
let bytes = from;
let text = bytes.try_copy_to_cheetah_string.unwrap;
assert_eq!;
let invalid = from_static;
let error = try_copy_from_bytes.unwrap_err;
assert_eq!;
The full executable contract is in
docs/bytes-interop.md.
Features
| Feature | Default | Contract |
|---|---|---|
std |
Yes | Standard-library integration |
serde |
No | Serialization and deserialization |
bytes |
No | CheetahBytes and explicit byte/text conversion |
experimental-simd |
No | Isolated x86_64 SSE2 benchmark path; not recommended for production |
simd |
No | Deprecated alpha compatibility alias for experimental-simd |
experimental-packed |
No | Unstable packed-representation prototype |
Optional features do not change the stable CheetahString layout.
Performance evidence
The repository includes RocketMQ-shaped Criterion workloads for property building, remoting-header parsing, topic insertion and lookup, plus explicit layout and allocation contracts. Blocking timing decisions run only on a dedicated fixed CPU with two reversed base/head rounds.
Thresholds, metadata requirements, and reproduction commands are documented in
docs/performance-gates.md. Hosted-runner and local
benchmark results are diagnostic; they do not independently establish a
release-grade performance pass.
The architecture/optimization design scores 96/100 only when all 14 versioned conditions are evidenced. PR performance may pass while that aggregate remains incomplete; final comparison only certifies its performance scope, while release verification fails closed on every missing live attestation. See the release evidence discovery contract.
Safety and portability
Every deterministic CI run covers formatting, Clippy, Rust 1.75, all features,
no_std, exact layout, and allocation contracts. Nightly validation adds Miri,
Linux AddressSanitizer, transition fuzzing, and split differential fuzzing.
The unsafe constructors are explicitly named and require the caller to prove UTF-8 validity. Safe byte constructors validate before creating text.
The historical local diagnostic record, with its own candidate identity,
execution counts, exclusions, and SHA-256 log digests, is in
bench-results/safety/2026-07-26-local/summary.md.
Historical downstream compile and representative-test diagnostics are in the
archived crater summary.
Neither record substitutes for an exact-candidate release attestation. The
stable unsafe-site inventory is in
docs/stable-unsafe-audit.md.
Migration and architecture
- v2 to v3 migration
- ADR 001: immutable canonical value
- ADR 002: bytes copy boundary
- ADR 003: SIMD policy
- ADR 004: split capability
- ADR 005: performance gates
- ADR 006: rejected packed boundary
The v3 alpha temporarily retains several deprecated v2 spellings so large read-only consumers can validate the new representation incrementally. Deprecated names do not retain mutable v2 semantics.
Projects using CheetahString
License
Licensed under either of Apache License 2.0 or MIT, at your option.