From 9339a6f8f35ff320f89d10b644b1b131facb4aaa Mon Sep 17 00:00:00 2001 From: behzad nouri Date: Thu, 20 May 2021 16:08:38 -0400 Subject: [PATCH] locks gossip only once in push_epoch_slots push_epoch_slots is unlocking and locking again gossip when iterating over epoch slot indices which is wasteful: https://github.com/solana-labs/solana/blob/0486df02b/core/src/cluster_info.rs#L915-L929 --- core/src/cluster_info.rs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/core/src/cluster_info.rs b/core/src/cluster_info.rs index 75d54a8f1d..594324b257 100644 --- a/core/src/cluster_info.rs +++ b/core/src/cluster_info.rs @@ -900,23 +900,20 @@ impl ClusterInfo { } } - pub fn push_epoch_slots(&self, update: &[Slot]) { + pub(crate) fn push_epoch_slots(&self, update: &[Slot]) { let mut num = 0; - let mut current_slots: Vec<_> = (0..crds_value::MAX_EPOCH_SLOTS) - .filter_map(|ix| { - Some(( - self.time_gossip_read_lock( - "lookup_epoch_slots", - &self.stats.epoch_slots_lookup, - ) - .crds - .lookup(&CrdsValueLabel::EpochSlots(ix, self.id())) - .and_then(CrdsValue::epoch_slots) - .and_then(|x| Some((x.wallclock, x.first_slot()?)))?, - ix, - )) - }) - .collect(); + let mut current_slots: Vec<_> = { + let gossip = + self.time_gossip_read_lock("lookup_epoch_slots", &self.stats.epoch_slots_lookup); + (0..crds_value::MAX_EPOCH_SLOTS) + .filter_map(|ix| { + let label = CrdsValueLabel::EpochSlots(ix, self.id()); + let epoch_slots = gossip.crds.get(&label)?.value.epoch_slots()?; + let first_slot = epoch_slots.first_slot()?; + Some(((epoch_slots.wallclock, first_slot), ix)) + }) + .collect() + }; current_slots.sort_unstable(); let min_slot: Slot = current_slots .iter()