-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Put font data into Arc to reduce memory consumption #5276
Put font data into Arc to reduce memory consumption #5276
Conversation
E.g. it keeps a copy in egui/crates/egui/src/context.rs Line 599 in 707cd03
from: egui/crates/egui/src/context.rs Lines 587 to 601 in 707cd03
|
Preview available at https://egui-pr-preview.github.io/pr/5276-pr_reduce_memory_usage_font_definitions |
Let's wait until after #5228 is merged |
26d52dc
to
e624075
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>>,
e624075
to
18be843
Compare
FontDefinitions
cloning, wrap it in Arc
Sounds good aswell |
753d87c
to
522b1ad
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better!
And additionally make cloning `FontDefinitions` cheaper.
522b1ad
to
bef08ec
Compare
egui never accesses the
FontDefinitions
' member fields mutably, except infonts_tweak_ui
where it cloned theFontDefinitions
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.