Skip to content

Specialize BytesMut::extend<u8> when its Vec-backed - #829

Merged
GlenDC merged 3 commits into
tokio-rs:masterfrom
AdamGS:adamg/specialize-extended-vec
Nov 9, 2026
Merged

GlenDC merged 3 commits into
tokio-rs:masterfrom
AdamGS:adamg/specialize-extended-vec

Conversation

@AdamGS

@AdamGS AdamGS commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds a specialized code path to extending BytesMut when its backed by a Vec. There are no external changes, only a private function and type with some tests.

When benchmarking on my laptop (M3 Max MacBook Pro), the change to put_slice_vec_extend is from 480 MB/s to over 9000MB/s. Happy to bench on some Intel hardware if the data is interesting.

@AdamGS AdamGS changed the title Specialize BytesMut::extend when its Vec-backed Specialize BytesMut::extend<u8> when its Vec-backed Jun 15, 2026
@AdamGS
AdamGS force-pushed the adamg/specialize-extended-vec branch from 02decdb to dc47673 Compare June 15, 2026 19:04
@AdamGS

AdamGS commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Messed up an unsafe block, now fixed

Signed-off-by: Adam Gutglick <[email protected]>
@AdamGS
AdamGS force-pushed the adamg/specialize-extended-vec branch from 444fb1b to 8884ead Compare September 16, 2026 11:13
@AdamGS

AdamGS commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

I've made another pass at this PR to simplify it. Its mush smaller and simpler now while still having the same performance.

@itsjunetime

Copy link
Copy Markdown

This seems reasonable to me and would be a nice improvement. I would also appreciate it if it were merged.

@GlenDC GlenDC left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, ~270 MB/s -> ~56 GB/s locally for slice iters. one nit inline. supersedes #849

Comment thread src/bytes_mut.rs Resolved
Comment thread src/bytes_mut.rs Resolved
@AdamGS

AdamGS commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

thanks for the review @GlenDC! I've addressed both comments.

@GlenDC

GlenDC commented Nov 9, 2026

Copy link
Copy Markdown
Member

lgtm now, thanks!

@GlenDC
GlenDC merged commit e0cdab7 into tokio-rs:master Nov 9, 2026
18 checks passed
@AdamGS
AdamGS deleted the adamg/specialize-extended-vec branch November 10, 2026 12:49
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.

3 participants