A library for encoding blobs into a 2D square of evenly sized chunks designed for sampling and reconstruction
Apache License 2.0
13
stars
16
forks
source link
shares: NamespacePaddingShare can take advantage of Go's memory guarantees to zero memory and use make([]byte, LEN) instead of bytes.Repeat([]byte{0}, LEN) which is less efficient #41
Those code snippets try to create zero byte slices of LEN. Go guarantees that all memory shall be zeroed per https://go.dev/ref/spec#The_zero_value and even better, make is made much more efficient than bytes.Repeat and quick benchmarks can prove this
Summary of Bug
While auditing this repository I noticed these code snippets https://github.com/celestiaorg/go-square/blob/4135f359b20ddd97b6cb74ecc831f70ffb73f8a5/shares/padding.go#L23
and
https://github.com/celestiaorg/go-square/blob/4135f359b20ddd97b6cb74ecc831f70ffb73f8a5/shares/utils.go#L34-L35
Insights
Those code snippets try to create zero byte slices of LEN. Go guarantees that all memory shall be zeroed per https://go.dev/ref/spec#The_zero_value and even better, make is made much more efficient than bytes.Repeat and quick benchmarks can prove this
Benchmarks
with this benchmark
which shows the improvements
/cc @elias-orijtech @liamsi
Version
4135f359b20ddd97b6cb74ecc831f70ffb73f8a5
Steps to Reproduce
Please see the details above
For Admin Use