compact_str
compact_str copied to clipboard
Improve perf of From<CompactString> for String in edge case
Originally implemented in #118, it might be possible to improve the performance of the edge case when we have a CompactString
> 16MB on 32-bit systems by re-using the already allocated buffer.
See this comment for more detail
Copying over my notes:
the layouts [of
String
's buffer and our heap allocated len+data] aren't compatible
Yeah, you'll run into an issue as String
's buffer is u8
aligned but the inline length is usize
aligned. At a performance cost, we could store the length unaligned to make the allocated alignment 1.
The unstable Allocator
trait allows requesting (though an implementation can theoretically refuse to fulfill) a change in alignment of an allocation. The stable GlobalAlloc
does not.
My vote is to just copy/realloc, and put a note tl if/when Allocator
is stabilized optimize it to opportunistically use a layout-adjusting realloc so the underlying allocator can avoid the copy.