1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 06:10:06 -04:00

Put font data into Arc to reduce memory consumption (#5276)

egui never accesses the `FontDefinitions`' member fields mutably, except
in `fonts_tweak_ui` where it cloned the `FontDefinitions` object anyway.

This patch reduces system memory consumption for shared font
definitions.
And also removes some overhead from copying (e.g. for the per
`pixel_per_points` font atlas)

Also it allows to keep a copy of the font definitions outside of egui.

In my App that uses international fonts:
Before:

![image](https://github.com/user-attachments/assets/f8dfb4f4-a21c-447c-8cf9-83025ad6e960)

New:

![image](https://github.com/user-attachments/assets/9f297fbd-e620-4b7e-a32a-65073ee805ed)


Note: If `Arc` is not wanted, then it could ofc be abstracted away.

I know this is quite a breaking change API wise, but would like to hear
your opinion.
This commit is contained in:
StarStarJ
2024-11-01 13:30:02 +01:00
committed by GitHub
parent 793cb92557
commit 3f5cd74de7
3 changed files with 25 additions and 14 deletions

View File

@@ -597,7 +597,9 @@ impl ContextImpl {
FontPriority::Lowest => fam.push(font.name.clone()),
}
}
self.font_definitions.font_data.insert(font.name, font.data);
self.font_definitions
.font_data
.insert(font.name, Arc::new(font.data));
}
#[cfg(feature = "log")]
@@ -2944,7 +2946,9 @@ impl Context {
for (name, data) in &mut font_definitions.font_data {
ui.collapsing(name, |ui| {
if data.tweak.ui(ui).changed() {
let mut tweak = data.tweak;
if tweak.ui(ui).changed() {
Arc::make_mut(data).tweak = tweak;
changed = true;
}
});