# 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:** 29

<div class="post-metadata">

**Author:** ![mcy](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mcy/32/6512_2.png) [@mcy](https://internals.rust-lang.org/u/mcy)\
**Post date:** [September 25, 2018, 2:43pm UTC](https://internals.rust-lang.org/t/short-string-optimization/8436/29 "2018-09-25T14:43:18Z")

</div>

> [@notriddle](#):
>
> Then all of the String functions would have to check whether the String is heap-allocated or inlined, despite the HeapString guaranteeing that the branch only goes one way.

Yeah, there's no particularly good way to optimize those calls in today's compiler. I mumbled something about how `is_heap` should be annotated to predict true (Does Rust even have a way to do this? Clang has some kind of non-standard attr I think.) or whatever, but I have nothing concrete to say as to the performance hit.

> [@pepp](#):
>
> The only argument that has any solid ground here is that someone measures that SSO will improve performance of majority of existing rust code.

Yeah, that's what I've been saying. Absent that, I don't think making `std::string::String` an SSO string is worth it.

I'm glad to see the discussion this has generated. I think the issue is cleared up for me!

---

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