Trim text Buffer cache every frame in iced_wgpu and iced_tiny_skia
This commit is contained in:
parent
c8f637fc16
commit
ea50ec8df1
2 changed files with 9 additions and 27 deletions
|
|
@ -246,6 +246,8 @@ struct GlyphCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GlyphCache {
|
impl GlyphCache {
|
||||||
|
const TRIM_INTERVAL: usize = 300;
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
GlyphCache::default()
|
GlyphCache::default()
|
||||||
}
|
}
|
||||||
|
|
@ -328,7 +330,7 @@ impl GlyphCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn trim(&mut self) {
|
pub fn trim(&mut self) {
|
||||||
if self.trim_count > 300 {
|
if self.trim_count > Self::TRIM_INTERVAL {
|
||||||
self.entries
|
self.entries
|
||||||
.retain(|key, _| self.recently_used.contains(key));
|
.retain(|key, _| self.recently_used.contains(key));
|
||||||
|
|
||||||
|
|
@ -345,7 +347,6 @@ struct Cache<'a> {
|
||||||
entries: FxHashMap<KeyHash, cosmic_text::Buffer<'a>>,
|
entries: FxHashMap<KeyHash, cosmic_text::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"))]
|
||||||
|
|
@ -355,14 +356,11 @@ 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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -407,16 +405,10 @@ impl<'a> Cache<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trim(&mut self) {
|
fn trim(&mut self) {
|
||||||
if self.trim_count >= Self::TRIM_INTERVAL {
|
self.entries
|
||||||
self.entries
|
.retain(|key, _| self.recently_used.contains(key));
|
||||||
.retain(|key, _| self.recently_used.contains(key));
|
|
||||||
|
|
||||||
self.recently_used.clear();
|
self.recently_used.clear();
|
||||||
|
|
||||||
self.trim_count = 0;
|
|
||||||
} else {
|
|
||||||
self.trim_count += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -321,7 +321,6 @@ 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"))]
|
||||||
|
|
@ -331,14 +330,11 @@ 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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -387,16 +383,10 @@ impl<'a> Cache<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trim(&mut self) {
|
fn trim(&mut self) {
|
||||||
if self.trim_count >= Self::TRIM_INTERVAL {
|
self.entries
|
||||||
self.entries
|
.retain(|key, _| self.recently_used.contains(key));
|
||||||
.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