# Short String optimization

**URL:** <https://internals.rust-lang.org/t/short-string-optimization/8436>\
**Category:** Uncategorized\
**Created:** [September 20, 2018, 3:55pm UTC](https://internals.rust-lang.org/t/short-string-optimization/8436 "2018-09-20T15:55:36Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![pepp](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pepp/32/1847_2.png) [@pepp](https://internals.rust-lang.org/u/pepp)\
**Post date:** [September 20, 2018, 5:10pm UTC](https://internals.rust-lang.org/t/short-string-optimization/8436/9 "2018-09-20T17:10:27Z")

</div>

> [@mcy](#):
>
> Has there been any discussion of having `String` live entirely on the stack for `len < size_of::<usize>() * n` ?

There have been some conversations in the past:

> <https://github.com/rust-lang/rust/issues/20198>
>
> SSO is a popular optimization technique and is currently implemented in all the …major C++ standard libraries\*.
> If Rust decides to adopt it too then it will come into contradiction with the \`String::as\_mut\_vec\` method, which exposes details of the current \`String\` implementation incompatible with SSO.
> I suppose, the choice between these two has to be made before marking \`as\_mut\_vec\` as stable.
> 
> \<sub\>\*Although it's not used by default in libstdc++ due to ABI compatibility\</sub\>

and

> [@Small string optimization: remove as\_mut\_vec](https://internals.rust-lang.org/t/small-string-optimization-remove-as-mut-vec/1320):
>
> I needed to create this thread, since I haven’t found too much dicussions on that topic. SSO is an important optimization in modern languages. To give an example: More than half of all allocations in the chromium browser are std::string allocations [1]. I don’t have a study or article around to prove the statement, but: You can easily imagine that many strings in applications won’t exceed a certain length. Storing those strings without allocating in the stack-object itself would be a huge gain …

---

_[View the full topic](https://internals.rust-lang.org/t/short-string-optimization/8436)._
