Cleanup - program runtime (#34318)

* Removes retain() from prune_by_deployment_slot() as that is covered in remove_programs_with_no_entries() already.

* Removes remove_programs_with_no_entries() from sort_and_unload().

* Fixes ix_usage_counter in LoadedProgram::to_unloaded().

* Fixes doc comment of LoadedProgram::ix_usage_counter.

* Removes unused num_total_programs from test_eviction().

* Replaces .as_ref() in lambda with std::option::Option::as_ref.

* Replaces .for_each() with a for-loop.

* Uses .retain() instead of iter().filter().cloned().collect().
This commit is contained in:
Alexander Meißner 2023-12-06 22:05:26 +01:00 committed by GitHub
parent b1c701e53b
commit cf0c52c207
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 18 deletions

View File

@ -615,7 +615,7 @@ impl<'a> InvokeContext<'a> {
pub fn get_syscall_context(&self) -> Result<&SyscallContext, InstructionError> {
self.syscall_context
.last()
.and_then(|syscall_context| syscall_context.as_ref())
.and_then(std::option::Option::as_ref)
.ok_or(InstructionError::CallDepth)
}

View File

@ -139,7 +139,7 @@ pub struct LoadedProgram {
pub maybe_expiration_slot: Option<Slot>,
/// How often this entry was used by a transaction
pub tx_usage_counter: AtomicU64,
/// How often this entry was used by a transaction
/// How often this entry was used by an instruction
pub ix_usage_counter: AtomicU64,
}
@ -371,7 +371,7 @@ impl LoadedProgram {
effective_slot: self.effective_slot,
maybe_expiration_slot: self.maybe_expiration_slot,
tx_usage_counter: AtomicU64::new(self.tx_usage_counter.load(Ordering::Relaxed)),
ix_usage_counter: AtomicU64::new(self.tx_usage_counter.load(Ordering::Relaxed)),
ix_usage_counter: AtomicU64::new(self.ix_usage_counter.load(Ordering::Relaxed)),
})
}
@ -646,14 +646,9 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
}
pub fn prune_by_deployment_slot(&mut self, slot: Slot) {
self.entries.retain(|_key, second_level| {
*second_level = second_level
.iter()
.filter(|entry| entry.deployment_slot != slot)
.cloned()
.collect();
!second_level.is_empty()
});
for second_level in self.entries.values_mut() {
second_level.retain(|entry| entry.deployment_slot != slot);
}
self.remove_programs_with_no_entries();
}
@ -917,7 +912,6 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
.len()
.saturating_sub(shrink_to.apply_to(MAX_LOADED_ENTRY_COUNT));
self.unload_program_entries(sorted_candidates.iter().take(num_to_unload));
self.remove_programs_with_no_entries();
}
/// Removes all the entries at the given keys, if they exist
@ -929,7 +923,7 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
fn unload_program(&mut self, id: &Pubkey) {
if let Some(entries) = self.entries.get_mut(id) {
entries.iter_mut().for_each(|entry| {
for entry in entries.iter_mut() {
if let Some(unloaded) = entry.to_unloaded() {
*entry = Arc::new(unloaded);
self.stats
@ -938,7 +932,7 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
.and_modify(|c| saturating_add_assign!(*c, 1))
.or_insert(1);
}
});
}
}
}
@ -1131,7 +1125,6 @@ mod tests {
#[test]
fn test_eviction() {
let mut programs = vec![];
let mut num_total_programs: usize = 0;
let mut cache = new_mock_cache::<TestForkGraph>();
@ -1151,7 +1144,6 @@ mod tests {
AtomicU64::new(usage_counter),
),
);
num_total_programs += 1;
programs.push((program1, *deployment_slot, usage_counter));
});
@ -1185,7 +1177,6 @@ mod tests {
AtomicU64::new(usage_counter),
),
);
num_total_programs += 1;
programs.push((program2, *deployment_slot, usage_counter));
});
@ -1218,7 +1209,6 @@ mod tests {
AtomicU64::new(usage_counter),
),
);
num_total_programs += 1;
programs.push((program3, *deployment_slot, usage_counter));
});