Skip to content

Mark BytesMut::extend_from_slice as inline#1

Merged
samanpa merged 2 commits intomasterfrom
inline_extend_from_size
Feb 4, 2023
Merged

Mark BytesMut::extend_from_slice as inline#1
samanpa merged 2 commits intomasterfrom
inline_extend_from_size

Conversation

@samanpa
Copy link
Copy Markdown
Owner

@samanpa samanpa commented Feb 4, 2023

BytesMut::extend_from_slice , <BytesMut as BufMut>::put_u8 and <BytesMut as BufMut>::put_slice can be bottlenecks when encoding certain messages. This PR just marks extend_from_slice as inline since it is probably an easier change to accept.

example benchmark with these changes applied. Involves encoding a struct in ASN.1

$ hyperfine ./target/release/benchber ./target/release/benchber.orig 
Benchmark 1: ./target/release/benchber
  Time (mean ± σ):      1.179 s ±  0.067 s    [User: 0.937 s, System: 0.226 s]
  Range (min … max):    1.055 s …  1.257 s    10 runs
 
Benchmark 2: ./target/release/benchber.orig
  Time (mean ± σ):      1.935 s ±  0.101 s    [User: 1.686 s, System: 0.233 s]
  Range (min … max):    1.795 s …  2.159 s    10 runs

Summary
  './target/release/benchber' ran
    1.64 ± 0.13 times faster than './target/release/benchber.orig

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`.
@samanpa samanpa merged commit 6ad5de0 into master Feb 4, 2023
@samanpa samanpa deleted the inline_extend_from_size branch February 4, 2023 18:59
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.

1 participant