Trim Cache every 300 frames in text::Pipeline
This commit is contained in:
parent
17a4d817c4
commit
51844c5d0c
1 changed files with 13 additions and 3 deletions
|
|
@ -316,6 +316,7 @@ struct Cache<'a> {
|
||||||
entries: FxHashMap<KeyHash, glyphon::Buffer<'a>>,
|
entries: FxHashMap<KeyHash, glyphon::Buffer<'a>>,
|
||||||
recently_used: FxHashSet<KeyHash>,
|
recently_used: FxHashSet<KeyHash>,
|
||||||
hasher: HashBuilder,
|
hasher: HashBuilder,
|
||||||
|
trim_count: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
|
@ -325,11 +326,14 @@ type HashBuilder = twox_hash::RandomXxHashBuilder64;
|
||||||
type HashBuilder = std::hash::BuildHasherDefault<twox_hash::XxHash64>;
|
type HashBuilder = std::hash::BuildHasherDefault<twox_hash::XxHash64>;
|
||||||
|
|
||||||
impl<'a> Cache<'a> {
|
impl<'a> Cache<'a> {
|
||||||
|
const TRIM_INTERVAL: usize = 300;
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
entries: FxHashMap::default(),
|
entries: FxHashMap::default(),
|
||||||
recently_used: FxHashSet::default(),
|
recently_used: FxHashSet::default(),
|
||||||
hasher: HashBuilder::default(),
|
hasher: HashBuilder::default(),
|
||||||
|
trim_count: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -389,10 +393,16 @@ impl<'a> Cache<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trim(&mut self) {
|
fn trim(&mut self) {
|
||||||
self.entries
|
if self.trim_count >= Self::TRIM_INTERVAL {
|
||||||
.retain(|key, _| self.recently_used.contains(key));
|
self.entries
|
||||||
|
.retain(|key, _| self.recently_used.contains(key));
|
||||||
|
|
||||||
self.recently_used.clear();
|
self.recently_used.clear();
|
||||||
|
|
||||||
|
self.trim_count = 0;
|
||||||
|
} else {
|
||||||
|
self.trim_count += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue