The itoa and ryu crates (the same crates serde_json uses) avoid allocating anything when serializing integers and floats.
By switching the code to work on bytes instead of &strs, expensive Unicode handling can be avoided (e.g. str::bytes is a lot cheaper to run than str::chars).
We can copy serde_json and start serialization with a capacity of 128, to avoid excessive reallocations.
Since we use bytes now we might as well expose ser::to_bytes.
Edit: I came back to this and overrode Serializer::collect_str because we can provide a more efficient implementation than the default.
itoa
andryu
crates (the same cratesserde_json
uses) avoid allocating anything when serializing integers and floats.&str
s, expensive Unicode handling can be avoided (e.g.str::bytes
is a lot cheaper to run thanstr::chars
).serde_json
and start serialization with a capacity of 128, to avoid excessive reallocations.ser::to_bytes
.Serializer::collect_str
because we can provide a more efficient implementation than the default.