decode: Use Decoder by pointer always
Most of the functions in ogorek.go already use Decoder by pointer, but NewDecoder() and Decoder.Decode() exceptionally used it by value. This was probably an oversight because when Decoder struct is used by value it is copied on every Decode call and also it is not possible to change and retain state in between calls as all changed happen to copy and then forgotten. This also leads to many unnnecessary allocations, i.e. memory allocated for stack one Decode call is not reused on next Decode call etc. So use Decoder by pointer only. This leads to the following speedup: name old time/op new time/op delta Speed-4 377ns ± 0% 383ns ± 4% ~ (p=0.214 n=5+5) Decode-4 80.4µs ± 3% 72.1µs ± 1% -10.38% (p=0.008 n=5+5) Encode-4 16.5µs ± 1% 16.5µs ± 0% ~ (p=0.690 n=5+5) name old alloc/op new alloc/op delta Speed-4 280B ± 0% 280B ± 0% ~ (all equal) Decode-4 44.0kB ± 0% 35.7kB ± 0% -18.77% (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% 429 ± 0% -14.54% (p=0.008 n=5+5) Encode-4 297 ± 0% 297 ± 0% ~ (all equal)
Showing
Please register or sign in to comment