Skip to content

perf: improve BufList::copy_to_bytes if len == remaining#112

Merged
seanmonstar merged 1 commit intomasterfrom
to-bytes-without-take
Mar 11, 2024
Merged

perf: improve BufList::copy_to_bytes if len == remaining#112
seanmonstar merged 1 commit intomasterfrom
to-bytes-without-take

Conversation

@seanmonstar
Copy link
Copy Markdown
Member

Using take(len) costs a bit in performance. If copying the full thing (which is what Collected::to_bytes() does), we can skip using take(n) and see a significant speed up.

Using hyper's body benchmarks, on my tiny VM, the perf improvement is from 5GB/s to 31GB/s.

@yanns
Copy link
Copy Markdown

yanns commented Mar 11, 2024

I've tried this change. All tests are passing.

My observation on production-like traffic: tokio-rs/axum#2381 (reply in thread)

@seanmonstar seanmonstar merged commit 76b19e6 into master Mar 11, 2024
@seanmonstar seanmonstar deleted the to-bytes-without-take branch March 11, 2024 18:53
@seanmonstar
Copy link
Copy Markdown
Member Author

Published in http-body-util v0.1.1.

@yanns
Copy link
Copy Markdown

yanns commented Mar 12, 2024

Thanks!
We've updated, and the performance issues are fixed for us.

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