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:
parent
b1c701e53b
commit
cf0c52c207
|
@ -615,7 +615,7 @@ impl<'a> InvokeContext<'a> {
|
||||||
pub fn get_syscall_context(&self) -> Result<&SyscallContext, InstructionError> {
|
pub fn get_syscall_context(&self) -> Result<&SyscallContext, InstructionError> {
|
||||||
self.syscall_context
|
self.syscall_context
|
||||||
.last()
|
.last()
|
||||||
.and_then(|syscall_context| syscall_context.as_ref())
|
.and_then(std::option::Option::as_ref)
|
||||||
.ok_or(InstructionError::CallDepth)
|
.ok_or(InstructionError::CallDepth)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -139,7 +139,7 @@ pub struct LoadedProgram {
|
||||||
pub maybe_expiration_slot: Option<Slot>,
|
pub maybe_expiration_slot: Option<Slot>,
|
||||||
/// How often this entry was used by a transaction
|
/// How often this entry was used by a transaction
|
||||||
pub tx_usage_counter: AtomicU64,
|
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,
|
pub ix_usage_counter: AtomicU64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +371,7 @@ impl LoadedProgram {
|
||||||
effective_slot: self.effective_slot,
|
effective_slot: self.effective_slot,
|
||||||
maybe_expiration_slot: self.maybe_expiration_slot,
|
maybe_expiration_slot: self.maybe_expiration_slot,
|
||||||
tx_usage_counter: AtomicU64::new(self.tx_usage_counter.load(Ordering::Relaxed)),
|
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) {
|
pub fn prune_by_deployment_slot(&mut self, slot: Slot) {
|
||||||
self.entries.retain(|_key, second_level| {
|
for second_level in self.entries.values_mut() {
|
||||||
*second_level = second_level
|
second_level.retain(|entry| entry.deployment_slot != slot);
|
||||||
.iter()
|
}
|
||||||
.filter(|entry| entry.deployment_slot != slot)
|
|
||||||
.cloned()
|
|
||||||
.collect();
|
|
||||||
!second_level.is_empty()
|
|
||||||
});
|
|
||||||
self.remove_programs_with_no_entries();
|
self.remove_programs_with_no_entries();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -917,7 +912,6 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
|
||||||
.len()
|
.len()
|
||||||
.saturating_sub(shrink_to.apply_to(MAX_LOADED_ENTRY_COUNT));
|
.saturating_sub(shrink_to.apply_to(MAX_LOADED_ENTRY_COUNT));
|
||||||
self.unload_program_entries(sorted_candidates.iter().take(num_to_unload));
|
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
|
/// 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) {
|
fn unload_program(&mut self, id: &Pubkey) {
|
||||||
if let Some(entries) = self.entries.get_mut(id) {
|
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() {
|
if let Some(unloaded) = entry.to_unloaded() {
|
||||||
*entry = Arc::new(unloaded);
|
*entry = Arc::new(unloaded);
|
||||||
self.stats
|
self.stats
|
||||||
|
@ -938,7 +932,7 @@ impl<FG: ForkGraph> LoadedPrograms<FG> {
|
||||||
.and_modify(|c| saturating_add_assign!(*c, 1))
|
.and_modify(|c| saturating_add_assign!(*c, 1))
|
||||||
.or_insert(1);
|
.or_insert(1);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1131,7 +1125,6 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_eviction() {
|
fn test_eviction() {
|
||||||
let mut programs = vec![];
|
let mut programs = vec![];
|
||||||
let mut num_total_programs: usize = 0;
|
|
||||||
|
|
||||||
let mut cache = new_mock_cache::<TestForkGraph>();
|
let mut cache = new_mock_cache::<TestForkGraph>();
|
||||||
|
|
||||||
|
@ -1151,7 +1144,6 @@ mod tests {
|
||||||
AtomicU64::new(usage_counter),
|
AtomicU64::new(usage_counter),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
num_total_programs += 1;
|
|
||||||
programs.push((program1, *deployment_slot, usage_counter));
|
programs.push((program1, *deployment_slot, usage_counter));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1185,7 +1177,6 @@ mod tests {
|
||||||
AtomicU64::new(usage_counter),
|
AtomicU64::new(usage_counter),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
num_total_programs += 1;
|
|
||||||
programs.push((program2, *deployment_slot, usage_counter));
|
programs.push((program2, *deployment_slot, usage_counter));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1218,7 +1209,6 @@ mod tests {
|
||||||
AtomicU64::new(usage_counter),
|
AtomicU64::new(usage_counter),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
num_total_programs += 1;
|
|
||||||
programs.push((program3, *deployment_slot, usage_counter));
|
programs.push((program3, *deployment_slot, usage_counter));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue