From 044d72064f783e18807d7837116bf7d1a7aaa852 Mon Sep 17 00:00:00 2001 From: Jim McDonald Date: Mon, 2 Mar 2020 15:00:23 +0000 Subject: [PATCH] Pre-allocate slices when reporting validator performance (#4979) --- beacon-chain/rpc/beacon/validators.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/beacon-chain/rpc/beacon/validators.go b/beacon-chain/rpc/beacon/validators.go index a391fa54e8..7ccf9599a4 100644 --- a/beacon-chain/rpc/beacon/validators.go +++ b/beacon-chain/rpc/beacon/validators.go @@ -584,15 +584,16 @@ func (bs *Server) GetValidatorPerformance( ) (*ethpb.ValidatorPerformanceResponse, error) { validatorSummary := state.ValidatorSummary - beforeTransitionBalances := make([]uint64, 0) - afterTransitionBalances := make([]uint64, 0) - effectiveBalances := make([]uint64, 0) - inclusionSlots := make([]uint64, 0) - inclusionDistances := make([]uint64, 0) - correctlyVotedSource := make([]bool, 0) - correctlyVotedTarget := make([]bool, 0) - correctlyVotedHead := make([]bool, 0) - missingValidators := make([][]byte, 0) + reqPubKeysCount := len(req.PublicKeys) + beforeTransitionBalances := make([]uint64, 0, reqPubKeysCount) + afterTransitionBalances := make([]uint64, 0, reqPubKeysCount) + effectiveBalances := make([]uint64, 0, reqPubKeysCount) + inclusionSlots := make([]uint64, 0, reqPubKeysCount) + inclusionDistances := make([]uint64, 0, reqPubKeysCount) + correctlyVotedSource := make([]bool, 0, reqPubKeysCount) + correctlyVotedTarget := make([]bool, 0, reqPubKeysCount) + correctlyVotedHead := make([]bool, 0, reqPubKeysCount) + missingValidators := make([][]byte, 0, reqPubKeysCount) // Convert the list of validator public keys to list of validator indices. // Also track missing validators using public keys.