I noticed some cases where Cow<str> is not enough.
For example, decoding a struct with a short lifetime reader requires a memory allocation for each fields name.
This is unnecessary, because we only need to judge whether the key is as expected, and we don't need to use it.
Also, the automatic allocation of memory on the heap makes it difficult for us to improve this.
I'm thinking of exposing the decode_buf interface in some form to get around this.
Change Decode trait
I considered changing the Decode trait to allow this optimization.
like
I noticed some cases where
Cow<str>
is not enough.For example, decoding a struct with a short lifetime reader requires a memory allocation for each fields name. This is unnecessary, because we only need to judge whether the key is as expected, and we don't need to use it. Also, the automatic allocation of memory on the heap makes it difficult for us to improve this.
I'm thinking of exposing the
decode_buf
interface in some form to get around this.Change
Decode
traitI considered changing the
Decode
trait to allow this optimization. likeThis allows decoding the object without allocating any memory, just identifying if it is as expected. will look like this
This also allows for more precise memory allocations, such as decode bytes to stack