diff options
author | 2023-02-10 18:52:35 +0100 | |
---|---|---|
committer | 2023-02-24 13:37:32 +0100 | |
commit | 51844c5d0c7f7c9b65c56330862b69f0baa0e3c1 (patch) | |
tree | a36d12bb86831f48c4c334e99a692bce265dba4a /wgpu | |
parent | 17a4d817c45da732e9fdc6559b6bbc7d5be94052 (diff) | |
download | iced-51844c5d0c7f7c9b65c56330862b69f0baa0e3c1.tar.gz iced-51844c5d0c7f7c9b65c56330862b69f0baa0e3c1.tar.bz2 iced-51844c5d0c7f7c9b65c56330862b69f0baa0e3c1.zip |
Trim `Cache` every 300 frames in `text::Pipeline`
Diffstat (limited to 'wgpu')
-rw-r--r-- | wgpu/src/text.rs | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index c0f49417..dea6ab18 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -316,6 +316,7 @@ struct Cache<'a> { entries: FxHashMap<KeyHash, glyphon::Buffer<'a>>, recently_used: FxHashSet<KeyHash>, hasher: HashBuilder, + trim_count: usize, } #[cfg(not(target_arch = "wasm32"))] @@ -325,11 +326,14 @@ type HashBuilder = twox_hash::RandomXxHashBuilder64; type HashBuilder = std::hash::BuildHasherDefault<twox_hash::XxHash64>; impl<'a> Cache<'a> { + const TRIM_INTERVAL: usize = 300; + fn new() -> Self { Self { entries: FxHashMap::default(), recently_used: FxHashSet::default(), hasher: HashBuilder::default(), + trim_count: 0, } } @@ -389,10 +393,16 @@ impl<'a> Cache<'a> { } fn trim(&mut self) { - self.entries - .retain(|key, _| self.recently_used.contains(key)); + if self.trim_count >= Self::TRIM_INTERVAL { + 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; + } } } |