Reduce the amount of `FontDefinitions` cloning, wrap it in `Arc`
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:
New:
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.
E.g. it keeps a copy in ContextImpl and copies it into the fonts per pixels_per_point:
https://github.com/emilk/egui/blob/707cd03357f926d040acb241a5c42d8e91a83d8e/crates/egui/src/context.rs#L599
from: https://github.com/emilk/egui/blob/707cd03357f926d040acb241a5c42d8e91a83d8e/crates/egui/src/context.rs#L587-L601
Preview available at https://egui-pr-preview.github.io/pr/5276-pr_reduce_memory_usage_font_definitions Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.
Let's wait until after https://github.com/emilk/egui/pull/5228 is merged
I think a simpler and smaller change would be
@@ -243,7 +243,7 @@ pub struct FontDefinitions { /// List of font names and their definitions. /// /// `epaint` has built-in-default for these, but you can override them if you like. - pub font_data: BTreeMap<String, FontData>, + pub font_data: BTreeMap<String, Arc<FontData>>,
Sounds good aswell