Skip to content

Conversation

@rrichardson
Copy link

Here are my proposed changes to the module structure as well as the naming, based on your PR.

I think it makes things quite a bit clearer, and the changes to support the module isolation/encapsulation were trivial to implement.

Unfortunately it doesn't diff very well.

MrGunflame and others added 4 commits January 31, 2023 11:42
When we freeze a BytesMut, we turn it into a Vec, and then convert that
to a Bytes.  Currently, this happen using Vec::into_boxed_slice, which
reallocates to a slice of the same length as the Vev if the length and
the capacity are not equal.  This can pose a performance problem if the
Vec is large or if this happens many times in a loop.

Instead, let's compare the length and capacity, and if they're the same,
continue to handle this using into_boxed_slice.  Otherwise, since we
have a type of vtable which can handle a separate capacity, the shared
vtable, let's turn our Vec into that kind of Bytes.  While this does not
avoid allocation altogether, it performs a fixed size allocation and
avoids any need to memcpy.
This function can be hot in applications that do a lot of encoding. Ideally would do the same for `<BytesMut as BufMut>::put_slice` and `<BytesMut as BufMut::put_u8`.
@rrichardson rrichardson force-pushed the refactor-api branch 2 times, most recently from 10f9006 to 9542890 Compare February 7, 2023 00:02
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.

10 participants