egui icon indicating copy to clipboard operation
egui copied to clipboard

Improving context creation overhead

Open mahkoh opened this issue 2 years ago • 2 comments

In my wayland compositor [1], I have the need to show a GUI to the user to perform certain actions. For example, when an application wants to do a screencapture, I have to show a window to allow the user to select the part of the screen to share.

I have been considering egui for this task but I have been hit by a roadblock. My approach is as follows: When a new GUI window is needed, create a new egui Context and render the window's content using egui. When the window is closed, destroy the context. At any time, any number of egui Contexts can exist.

The problem is that creating a new Context (actually rendering the first frame) is very slow and causes the whole desktop to lag. I assume this is because egui has to load its fonts anew for each Context.

Would it be possible to modify egui such that all of this setup cost only has to be paid one time? It would be acceptable for all of my contexts to share certain state, e.g. fonts, styling, etc.

[1] https://github.com/mahkoh/jay

mahkoh avatar Jun 06 '22 09:06 mahkoh

Not the first time this request came up. People wanted to share font textures between multiple viewports or windows etc..

Afaik, this is not a priority unless someone is willing to put effort in the design work first.

coderedart avatar Jun 06 '22 19:06 coderedart

egui::Context holds a epaint::Fonts which is a wrapper around an Arc<Mutex<…>>, so sharing fonts between multiple egui::Contexts should be fairly easy to implement, if anyone would care to make a PR! (as long as all contexts use the same pixels_per_point).

emilk avatar Jun 10 '22 09:06 emilk