From 81543971142c32c90cd9ecfc7085004aa22ec17b Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Thu, 14 Mar 2019 20:54:44 +1100 Subject: [PATCH] Set map initial cacacity in epoch cache builder This should help reduce reallocations --- eth2/types/src/beacon_state/epoch_cache.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eth2/types/src/beacon_state/epoch_cache.rs b/eth2/types/src/beacon_state/epoch_cache.rs index bbc991646..e6bacd351 100644 --- a/eth2/types/src/beacon_state/epoch_cache.rs +++ b/eth2/types/src/beacon_state/epoch_cache.rs @@ -33,12 +33,13 @@ impl EpochCache { ) -> Result { let mut epoch_committees: Vec = Vec::with_capacity(spec.slots_per_epoch as usize); - let mut attestation_duty_map: AttestationDutyMap = HashMap::new(); let mut shard_committee_index_map: ShardCommitteeIndexMap = HashMap::new(); let shuffling = state.get_shuffling_for_slot(epoch.start_slot(spec.slots_per_epoch), false, spec)?; + let mut attestation_duty_map: AttestationDutyMap = HashMap::with_capacity(shuffling.len()); + for (epoch_committeess_index, slot) in epoch.slot_iter(spec.slots_per_epoch).enumerate() { let slot_committees = state.calculate_crosslink_committees_at_slot( slot,