I wrote a zero allocation marshaller with mus-go for a struct that contains a lot of time.Time. Unfortunately, it still allocates because of time.MarshalBinary().
func(t time.Time) ReadBinary(p []byte) (int, error) (same as previous but does not satisfy io.Reader to avoid implementing a known interface for a specific encoding)
Proposal Details
Hi,
I wrote a zero allocation marshaller with mus-go for a struct that contains a lot of
time.Time
. Unfortunately, it still allocates because oftime.MarshalBinary()
.I played a bit with the standard library and implemented another version of
time.MarshalBinary() ([]byte, error)
that does not allocate (see: https://github.com/sylr/go/commit/384f060cc8da29846bc381beadbd6881010ebb3f).Here are the results:
I'm wondering if we could merge something like this, possible implementations I could think of are:
func(t time.Time) Read(p []byte) (int, error)
(what I implemented in https://github.com/sylr/go/commit/384f060cc8da29846bc381beadbd6881010ebb3f)func(t time.Time) ReadBinary(p []byte) (int, error)
(same as previous but does not satisfy io.Reader to avoid implementing a known interface for a specific encoding)type BinaryReader struct { Time }
func(r BinaryReader) Read(p []byte) (int, error)