Closed mmosky closed 4 months ago
Unmarshal
arguement is []byte
, which is MUTABLE in Golang thus must to be converted to be IMMUTABLE -- This is a standard way obey Golang's specs.
As for performance, you can choose to use UnmarshalFromString
or StreamDecoder
at first, it all depends on yourself - as long as YOU KNOW WHAT YOUR BUSINESS IS DOING
When using
sonic.Unmarshal
, unnecessary string and []byte conversions occur, leading to additional copies.Initially, the byte slice passed to
sonic.Unmarshal
is converted to a string, resulting in the first copy.Subsequently,
UnmarshalFromString
is invoked, internally employingbytes.NewBufferString
, which again converts the string back to a byte slice, resulting in the second copy.A simplest case: