Feature request: make every String a smartstring

I am not sure whether implementing the small string optimization in std is a good idea or not, but I think it should be possible to do in a backwards compatible way. Unfortunately, breaking of a bunch of crates which rely on unsound assumptions about String internals along the way.

According to my vague memories, std does not have the optimization because:

  • It simplifies the code base.
  • Behavior and performance of strings does not depend on compilation target.
  • Code does not have branching during string data access.

Can you link documentation which specifies those guaranties? I don't remember anything like this. If anything, the IP address debacle would point in the other direction. The closest thing is the representation section, but it only says that String has a pointer, a length, and a capacity, it has no restrictions on potentially implementing the small string optimization.

I think such reliance is quite suspicious and AFAIK, strictly speaking, is unsound.

Relevant older topic:

1 Like