Skip to content

Add #[inline] to BytesMut's BufMut::put_slice implementation - #860

Merged
Darksonn merged 1 commit into
masterfrom
patch/bytes-put-slice-inline
Oct 11, 2026
Merged

Darksonn merged 1 commit into
masterfrom
patch/bytes-put-slice-inline

Conversation

@GlenDC

@GlenDC GlenDC commented Oct 11, 2026

Copy link
Copy Markdown
Member

While optimizing Rama, I noticed that calls to BytesMut::put_slice
through generic BufMut code remained out of line in optimized builds
without cross-crate LTO.

The implementation simply delegates to BytesMut::extend_from_slice,
which already has #[inline]. Adding the same attribute to put_slice
allows it to inline across the crate boundary.

Compiler Explorer reproduction:
the generic BytesMut encoder retains calls to put_slice, while the
equivalent Vec<u8> encoder and direct extend_from_slice calls inline.

The online example uses bytes 1.10.1. I also reproduced this locally
with bytes 1.12.1 and confirmed that adding only #[inline] removes
the out-of-line put_slice calls.

@GlenDC GlenDC self-assigned this Oct 11, 2026
@Darksonn
Darksonn enabled auto-merge (squash) October 11, 2026 14:10
@Darksonn
Darksonn merged commit d38faf7 into master Oct 11, 2026
18 checks passed
@Darksonn
Darksonn deleted the patch/bytes-put-slice-inline branch October 11, 2026 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants