yeiin opened a new pull request, #194:
URL: https://github.com/apache/datasketches-go/pull/194
In tuple deserialization, `binary.Read` allocates a temporary buffer for
every entry hash, so decoding allocates once per retained entry. We can read
the hash into one buffer reused across the loop with `io.ReadFull`, which is
what `binary.Read` calls internally, so the bytes read and the errors stay the
same.
This applies to `Decoder.Decode` and `ArrayOfNumbersSketchDecoder.Decode`.
- Added tests that truncate encoded sketches at every byte of every hash and
check `io.EOF` / `io.ErrUnexpectedEOF`. They pass on main as well.
- Added `BenchmarkDecode` and `BenchmarkDecodeArrayOfNumbers`.
`assertUpdate` now takes `testing.TB` so the benchmarks can use it.
`go test ./tuple -run '^$' -bench BenchmarkDecode -count 6` on main
(fdcffae) and this branch, compared with benchstat:
```
goos: darwin
goarch: arm64
pkg: github.com/apache/datasketches-go/tuple
cpu: Apple M2 Pro
│ main.txt │ pr.txt │
│ sec/op │ sec/op vs base │
Decode-12 232.4µ ± 2% 152.1µ ± 1% -34.58% (p=0.002 n=6)
DecodeArrayOfNumbers-12 432.5µ ± 1% 368.8µ ± 1% -14.73% (p=0.002 n=6)
geomean 317.1µ 236.8µ -25.31%
│ main.txt │ pr.txt
│
│ B/op │ B/op vs base
│
Decode-12 171.3Ki ± 0% 129.7Ki ± 0% -24.28% (p=0.002 n=6)
DecodeArrayOfNumbers-12 510.5Ki ± 0% 468.9Ki ± 0% -8.15% (p=0.002 n=6)
geomean 295.7Ki 246.6Ki -16.60%
│ main.txt │ pr.txt │
│ allocs/op │ allocs/op vs base │
Decode-12 15.98k ± 0% 10.66k ± 0% -33.30% (p=0.002 n=6)
DecodeArrayOfNumbers-12 26.63k ± 0% 21.31k ± 0% -19.99% (p=0.002 n=6)
geomean 20.63k 15.07k -26.95%
```
Both benchmark sketches retain 5,324 entries, and allocs/op drops by 5,323
in both: one allocation per entry is gone, and the reused buffer is allocated
once per decode. The remaining allocations come from the summary readers used
in these benchmarks, which also use `binary.Read`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]