tinylib / msgp

A Go code generator for MessagePack / msgpack.org[Go]
MIT License
1.79k stars 190 forks source link

Added Read/WriteExtensionRaw #329

Closed mhr3 closed 1 year ago

mhr3 commented 1 year ago

Our codebase is using Extensions quite extensively, and we've noticed that reading and writing an Extension with the current msgp API always causes an allocation, which is usually not the case when using any other msgp Read/Write methods. Therefore we've added Reader.ReadExtensionRaw() and Writer.WriteExtensionRaw() in this PR which allows zero-alloc code paths for extensions.

goos: darwin
goarch: arm64
pkg: github.com/tinylib/msgp/msgp
BenchmarkExtensionReadWrite/interface-8                13196         89295 ns/op        8377 B/op          1 allocs/op
BenchmarkExtensionReadWrite/raw-8                      13910         88740 ns/op        8299 B/op          0 allocs/op
PASS
ok      github.com/tinylib/msgp/msgp    4.329s