3 ms·
on interesting thing to realize is that some small string types go beyond just the basic small len storage optimization - compact_str e.g. depends on the strin
by dathinab 2y ago
on interesting thing to realize is that some small string types go beyond just the basic small len storage optimization
- compact_str e.g. depends on the string being valid utf-8, and in turn has larger short strings
- smol_str e.g. is a a enum over `[u8; CAP] | &'static str | Arc<str>` this means it avoids any allocations for static strings and has very fast clones, leading to similar perf. characteristics as string internalization in some use cases (like the use-cases it was designed for). But at the cost of it being immutable only and the heap allocation being slightly larger for the Rc.
Other interesting differences can be the handling of shrinking mutable Strings, do you re-inline it or not? What is better here is highly use-case dependent.
In the end there are many design decisions where there is no clear winner but it's a question of trade off with use-case specific preferences.