hyperium / http-body

Asynchronous HTTP body trait
MIT License
125 stars 49 forks source link

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

Closed seanmonstar closed 6 months ago

seanmonstar commented 6 months ago

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 commented 6 months ago

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

My observation on production-like traffic: https://github.com/tokio-rs/axum/discussions/2381#discussioncomment-8749626

seanmonstar commented 6 months ago

Published in http-body-util v0.1.1.

yanns commented 6 months ago

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