decode directly with a []byte
IPLD's codec helper reader has a relatively high cost, unfortunately. It was the main contributor to a slowdown in go-merkledag when moving from the old protobuf gogo-generated decoder to go-codec-dagpb. Using a []byte also means we can reuse protobuf's well-optimized "wire encoding" helpers, which gets us extra speed and allows removing some code. This should not matter in practice for the time being, as the only go-codec-dagpb user is go-merkledag and it uses bytes.Buffer everywhere. In the future it would be nice for go-codec-dagpb to be just as efficient with a stream decoder, but right now I don't have the extra week to get into that. Plus, if the core protobuf implementation works on []byte, one can assume it's reasonable for us to do the same. Using the new BenchmarkRoundtrip in go-merkledag with go-codec-dagpb, we get a significant uplift in performance: name old time/op new time/op delta Roundtrip-8 6.49µs ± 1% 5.34µs ± 1% -17.74% (p=0.002 n=6+6) name old alloc/op new alloc/op delta Roundtrip-8 8.07kB ± 0% 7.50kB ± 0% -7.04% (p=0.002 n=6+6) name old allocs/op new allocs/op delta Roundtrip-8 171 ± 0% 148 ± 0% -13.45% (p=0.002 n=6+6)
Showing
... | ... | @@ -5,5 +5,5 @@ go 1.15 |
require ( | ||
github.com/ipfs/go-cid v0.0.7 | ||
github.com/ipld/go-ipld-prime v0.9.0 | ||
github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e | ||
google.golang.org/protobuf v1.26.0 | ||
) |
Please register or sign in to comment