Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
Hey everyone! I just published a new crate called compact_str which provides a new immutable string type, CompactStr, that allocates up to 24 bytes on the stack (12 bytes for 32-bit architectures). This can be particularly useful when working with a lot of small strings, e.g. parsing data, and is more performant than a normal String.
Comparatively: * SmolStr can inline up to 22 bytes but does not adjust down for 32-bit architectures, meaning it's potentially wasting memory on 32-bit archs. Similarly though it's immutable and Clone is O(1) * SmartString can inline up to 23 bytes, but it's mutable and Clone is O(n). Also this crate makes assumptions about the memory layout of a String, which in theory should be fine, but is a slight caveat.
Comparatively: * SmolStr can inline up to 22 bytes but does not adjust down for 32-bit architectures, meaning it's potentially wasting memory on 32-bit archs. Similarly though it's immutable and Clone is O(1) * SmartString can inline up to 23 bytes, but it's mutable and Clone is O(n). Also this crate makes assumptions about the memory layout of a String, which in theory should be fine, but is a slight caveat.
Related posts
- Announcing `compact_str` version 0.7! A small string optimization for Rust
- Is there a type like `std::num::NonZero*` but for other values than zero?
- Announcing `compact_str` version 0.6! A small string optimization for Rust
- Announcing `compact_str` version 0.5! A small string optimization for Rust
- Announcing `compact_str` version 0.4! A small string optimization for Rust