mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 08:37:37 +00:00
stateutil: Reduce allocations by specifying slice capacity eager (#9977)
* Reduce allocations by specifying slice capacity eager * gofmt
This commit is contained in:
parent
d3c97da4e1
commit
3767574c77
@ -57,6 +57,7 @@ go_test(
|
||||
"state_root_test.go",
|
||||
"stateutil_test.go",
|
||||
"trie_helpers_test.go",
|
||||
"validator_root_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
|
@ -58,7 +58,7 @@ func ValidatorRootWithHasher(hasher ssz.HashFn, validator *ethpb.Validator) ([32
|
||||
// a list of uint64 and mixed with registry limit.
|
||||
func Uint64ListRootWithRegistryLimit(balances []uint64) ([32]byte, error) {
|
||||
hasher := hash.CustomSHA256Hasher()
|
||||
balancesMarshaling := make([][]byte, 0)
|
||||
balancesMarshaling := make([][]byte, 0, len(balances))
|
||||
for i := 0; i < len(balances); i++ {
|
||||
balanceBuf := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(balanceBuf, balances[i])
|
||||
|
22
beacon-chain/state/stateutil/validator_root_test.go
Normal file
22
beacon-chain/state/stateutil/validator_root_test.go
Normal file
@ -0,0 +1,22 @@
|
||||
package stateutil_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
|
||||
)
|
||||
|
||||
func BenchmarkUint64ListRootWithRegistryLimit(b *testing.B) {
|
||||
balances := make([]uint64, 100000)
|
||||
for i := 0; i < len(balances); i++ {
|
||||
balances[i] = uint64(i)
|
||||
}
|
||||
b.Run("100k balances", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := stateutil.Uint64ListRootWithRegistryLimit(balances)
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user