kisielk / og-rek

ogórek is a Go library for encoding and decoding pickles.
MIT License
60 stars 16 forks source link

decoder: Small speedups #35

Closed navytux closed 7 years ago

navytux commented 7 years ago

Hello up there. I've looked around a bit and prepared small speedups for decoder mainly by avoiding unnneccessary allocations. Overall it is:

name      old time/op    new time/op    delta
Speed-4      377ns ± 0%     379ns ± 1%     ~     (p=0.222 n=5+5)
Decode-4    80.4µs ± 3%    67.3µs ± 0%  -16.32%  (p=0.008 n=5+5)
Encode-4    16.5µs ± 1%    16.6µs ± 0%     ~     (p=0.222 n=5+5)

name      old alloc/op   new alloc/op   delta
Speed-4       280B ± 0%      280B ± 0%     ~     (all equal)
Decode-4    44.0kB ± 0%    31.0kB ± 0%  -29.50%  (p=0.008 n=5+5)
Encode-4    6.54kB ± 0%    6.54kB ± 0%     ~     (all equal)

name      old allocs/op  new allocs/op  delta
Speed-4       8.00 ± 0%      8.00 ± 0%     ~     (all equal)
Decode-4       502 ± 0%       326 ± 0%  -35.06%  (p=0.008 n=5+5)
Encode-4       297 ± 0%       297 ± 0%     ~     (all equal)

Please see details in individual commit messages.

Thanks beforehand, Kirill

kisielk commented 7 years ago

Unfortunate that this has to change the public API, but I guess it was a mistake to make it not return *Decoder in the first place

navytux commented 7 years ago

Yes, it was probably an overlook or thinko. Thanks for merging the patches.

kisielk commented 7 years ago

If you look at the original 2012 commit date it was from when I was a lot less experienced with Go :)

navytux commented 7 years ago

Yes, I understand. I was too only looking at go tour then. Anyway after those 5 years it seems to be appropriate time to correct :)