Rust String Benchmarks

March 10, 2026 ยท View on GitHub

This repo tries to assess Rust string types.

We currently compare:

NameSizeHeapInline&'static strMutableUnsafeNotes
String24 bytesY-NY-Universal
Cow<'static, str>24 bytesY-YN-
arcstr8 bytes??????
cold-string8 bytesY8 bytesNNY (miri, proptest)Space optimized for non-inline strings, 1 byte aligned (1 byte extra for Option<_>)
compact_str24 bytesY24 bytesYYY (miri, proptest, fuzz)Space optimized for Option<_>
ecow16 bytesY15 bytesNYY (miri)O(1) clone unless mutated, Space optimized for Option<_>
flexstr24 bytesY22 bytesYNY (miri)O(1) clone
hipstr24 bytesY23 bytesYYY (miri)O(1) clone, O(1) substring
imstr24 bytes??????
kstring24 bytesY15 bytesYNOptional (miri, proptest)Optional O(1) clone, optional 22 byte small string, Ref/Cow API for preserving &'static str
lean_string16 bytesY16 bytesYYY (miri, proptest)O(1) clone unless mutated, Space optimized for Option<_>
smartstring24 bytesY23 bytesNYY (miri, proptest, fuzz)

Suggestions:

  • Generally, String
  • If you deal mostly with string literals but want some flexibility (like clap), generally you'll want Cow<'static, str>
  • If a profiler says your strings are a problem:
    • Try different crates and settings for that crate out with a profiler
    • O(1) clones are important when doing a lot of clones. For one-off allocations, they are slower.
    • For short-lived programs, look into string interning

Note: smol_str was removed in favor of ecow

Terms:

  • Heap: will store strings in heap-allocated memory
  • Inline: will store small-enough strings on the stack

Results

new summary: new

See more details

clone summary: clone

See more details

access summary: access

(smartstring is skipped due to how slow it is)

See more details

self_eq summary: self_eq

See more details

Special Thanks