You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SmolStr allocates data on heap when size_hint of a iterator is above 24.
Even when the size hint is incorrect, it keeps it's data on heap, wrapped in Arc.
I want SmolStr to allocate it's contents on stack when the resulting data is turns out to be smaller.
Why do we need this
It allows us to introduce new optimization, reduce interaction with Arc... etc.
Proof
Here is an analysis of assembly code.
(I'm pretty sure that there is a better way to do this)
You can see that my optimization reduces number of instructions and improves uOps per cycle/IPC.
I do think we should have the invariant that when SmolStr is Heap backed, the string needs to be longer than the INLINE_CAP, the last release does have the extra check for if the size hint lies to fall back to inline.
Implementation
What we should do
SmolStr allocates data on heap when
size_hint
of a iterator is above24
.Even when the size hint is incorrect, it keeps it's data on heap, wrapped in
Arc
.I want
SmolStr
to allocate it's contents on stack when the resulting data is turns out to be smaller.Why do we need this
It allows us to introduce new optimization, reduce interaction with
Arc
... etc.Proof
Here is an analysis of assembly code.
(I'm pretty sure that there is a better way to do this)
You can see that my optimization reduces number of instructions and improves uOps per cycle/IPC.
Current version of the code.
https://rust.godbolt.org/z/Mh9GhYbM9
This one with my optimization.
https://rust.godbolt.org/z/3Gh8jacYK
The text was updated successfully, but these errors were encountered: