Make image Cache eviction strategy less aggressive in iced_wgpu
Instead of trimming unconditionally at the end of a frame, we now trim the cache only when there is a cache miss. This way, images that are not visible but still a part of the layout will stay cached. Eviction will only happen when the images are not a part of the UI for two consectuive frames.
This commit is contained in:
parent
fdcec03197
commit
493c36ac71
6 changed files with 41 additions and 5 deletions
|
|
@ -40,6 +40,7 @@ impl Memory {
|
|||
pub struct Cache {
|
||||
map: FxHashMap<u64, Memory>,
|
||||
hits: FxHashSet<u64>,
|
||||
should_trim: bool,
|
||||
}
|
||||
|
||||
impl Cache {
|
||||
|
|
@ -55,6 +56,8 @@ impl Cache {
|
|||
Err(_) => Memory::Invalid,
|
||||
};
|
||||
|
||||
self.should_trim = true;
|
||||
|
||||
self.insert(handle, memory);
|
||||
self.get(handle).unwrap()
|
||||
}
|
||||
|
|
@ -86,6 +89,11 @@ impl Cache {
|
|||
|
||||
/// Trim cache misses from cache
|
||||
pub fn trim(&mut self, atlas: &mut Atlas) {
|
||||
// Only trim if new entries have landed in the `Cache`
|
||||
if !self.should_trim {
|
||||
return;
|
||||
}
|
||||
|
||||
let hits = &self.hits;
|
||||
|
||||
self.map.retain(|k, memory| {
|
||||
|
|
@ -101,6 +109,7 @@ impl Cache {
|
|||
});
|
||||
|
||||
self.hits.clear();
|
||||
self.should_trim = false;
|
||||
}
|
||||
|
||||
fn get(&mut self, handle: &image::Handle) -> Option<&mut Memory> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue