whyrusleeping / cbor-gen

Codegen for cbor codecs on your types
MIT License
35 stars 25 forks source link

improve allocations in map serialization #105

Closed whyrusleeping closed 2 weeks ago

whyrusleeping commented 2 weeks ago

reuse buffers more and use optimized read paths when available.

Before:

why@sirius ~/c/cbor-gen (master)> go test ./testing -run XXX -bench=.
goos: linux
goarch: amd64
pkg: github.com/whyrusleeping/cbor-gen/testing
cpu: AMD Ryzen Threadripper 3970X 32-Core Processor
BenchmarkMarshaling-64           1856397           712.1 ns/op        48 B/op          1 allocs/op
BenchmarkUnmarshaling-64          199536          6274 ns/op        1777 B/op         21 allocs/op
BenchmarkLinkScan-64              729843          1645 ns/op         112 B/op          1 allocs/op
BenchmarkDeferred-64              505626          2223 ns/op          40 B/op          2 allocs/op
BenchmarkMapMarshaling-64        2326390           497.8 ns/op        50 B/op          3 allocs/op
BenchmarkMapUnmarshaling-64       140995          8113 ns/op        2043 B/op         36 allocs/op
PASS
ok      github.com/whyrusleeping/cbor-gen/testing   10.424s

After:

why@sirius ~/c/cbor-gen (master)> go test ./testing -run XXX -bench=.
goos: linux
goarch: amd64
pkg: github.com/whyrusleeping/cbor-gen/testing
cpu: AMD Ryzen Threadripper 3970X 32-Core Processor
BenchmarkMarshaling-64           1755950           722.5 ns/op        48 B/op          1 allocs/op
BenchmarkUnmarshaling-64          192193          6699 ns/op        1777 B/op         21 allocs/op
BenchmarkLinkScan-64              672280          1669 ns/op         112 B/op          1 allocs/op
BenchmarkDeferred-64              656348          2182 ns/op          40 B/op          2 allocs/op
BenchmarkMapMarshaling-64        2236473           536.9 ns/op        50 B/op          3 allocs/op
BenchmarkMapUnmarshaling-64       183109          6313 ns/op        1930 B/op         20 allocs/op
PASS
ok      github.com/whyrusleeping/cbor-gen/testing   8.893s