Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve perf of From<CompactString> for String in edge case #120

Open
ParkMyCar opened this issue Jun 21, 2022 · 1 comment
Open

Improve perf of From<CompactString> for String in edge case #120

ParkMyCar opened this issue Jun 21, 2022 · 1 comment

Comments

@ParkMyCar
Copy link
Owner

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

@CAD97
Copy link
Contributor

CAD97 commented Jun 21, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants