3Hren/msgpack-rust

Avoid allocation for each serialization [Feature]

wbrickner opened this issue · 1 comments

I love using rmp_serde, great work.

I'm interested in very high-performance client-server interactions.

One thing that bothers me about rmp_serde is that allocation is forced for each serialization (to_vec internally creates its own vector). This lowers performance, if I serialize millions of messages, I could have a pool of buffers amortizing allocation costs and increasing data-cache hits inside the CPU (for the later step when these buffers are read).

Would it be feasible to add a function like to_existing_vec(val: &T, buffer: &mut [u8])?

I am not familiar with the ownership mechanics inside the serializer, so I understand if this is turns out to actually be really hard or impossible.

You can use the rmp_serde::encode::write function for this! Vec implements std::io::Write for exactly this purpose.