-
Notifications
You must be signed in to change notification settings - Fork 968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
impl FromRequest for BytesMut #2548
Comments
I suppose that’s what axum would have to do as well. Since the body is an async stream you can’t get a mutable reference to the data until you’ve buffered the whole thing. axum doesn’t store the body as Bytes internally or anything. |
I'm pretty sure an efficient impl is possible, easy even. I'm surprised the |
Feature Request
Motivation
I'm working on a Fediverse server implementation, using axum as the web framework. Fediverse servers receive thousands of request every second, even for small instances, like the one I run, so performance is important. Because ActivityPub uses copious amounts of JSON, I figure it's best to use a high-performance JSON parser, like
simd-json
. However,simd-json
'ssimd_json::from_slice
takes a mutable byte slice rather than an immutable one, so I can't useBytes
for that.This is just one particular usecase, but I'm confident there are other performance-critical scenarios where you'd want a
BytesMut
value instead of aBytes
value.Proposal
In axum-core, add the impl, using the existing
Bytes
impl as a starting point.Alternatives
For my usecase, I could theoretically turn the
Bytes
value into aVec<u8>
and then into aBytesMut
, but that would likely involve expensive copy operations that would nullify the performance gains from usingsimd-json
.The text was updated successfully, but these errors were encountered: