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

Remove the Vec representation #739

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SabrinaJewson
Copy link

@SabrinaJewson SabrinaJewson commented Oct 13, 2024

Bytes currently has both a “Vec” and “shared” representation, lazily upgrading the former to the latter. I believe that originally, the “Vec” representation allowed for excess capacity, but now it only works when len == cap. Given that it only saves one heap allocation, which is probably made anyway most of the time (it’s made whenever one does .split, .truncate, .clone etc), I would like to know how worth it it actually is.

The main benefit of removing it would probably be the removal of atomics, meaning it might have a bigger performance impact on ARM. But I don’t have an ARM machine, so if someone could run some benchmarks (Hyper or Tonic or something) on ARM – ideally multithreaded ones – that would be appreciated.

Maybe there’s a use case for this optimization I’m missing. I find that pretty rare to be using Box<[u8]> so I’m somewhat doubtful.


This PR is very much unfinished, I just creäted for initial feedback on the idea, and benchmarking purposes.

@Darksonn
Copy link
Contributor

I'm skeptical that replacing a load-acquire with a normal load is worth adding extra allocations for the case where a Bytes is created and used but never cloned. My gut feeling is that there are plenty of people who create a Bytes without ever cloning it.

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

Successfully merging this pull request may close these issues.

2 participants