-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Remove lock from Context
#1732
Remove lock from Context
#1732
Conversation
This makes it possible to reference different parts of Ui mutably at the same time. With getter methods the context reference is bound to the self lifetime so it would be impossible to, for instance, use the painter and context at the same time.
This decouples the Painter reference lifetime from the Ui reference lifetime and thus allows mutably borrowing the Context at the same time as the Painter.
It is impossible to have multiple Ui instances alive at the same time because they contain a mutable reference to the Context, so passing a &mut [Ui] is not possible anymore.
This is possible since `Context` is no longer required to be Send + Sync.
Just merged this into my own fork of egui, so I have a few comments as I just migrated my egui application to base off of this:
If this PR is to be accepted, I would recommend something of a migration guide or some deep documentation of the developer-facing changes so projects can more easily migrate. But I can notice a performance improvement myself, and about a 1% size decrease. |
This is a very nice effort, but I am not so happy with the worsening ergonomics. Adding |
Will any work be done on this? This was very promising. |
I decided to go this route instead: Still, thanks so much for all the work in this PR 🙏 |
This PR removes the main lock in
Context
and changes some parts of the API to accommodate this change, mainly necessary to satisfy the borrow checker.This change brings the following advantages:
No more deadlocks, code that would create a deadlock now gives a compile time error.
Since
Context
is no longer required to beSend + Sync
, callback shapes can capture!Send + !Sync
types. For example thethree-d
context.Improves performance by a couple percent.
It is no longer possible to use the same
Context
to draw UI on multiple threads at the same time, which is bound to give incorrect results.Closes Consider making egui::Context !Send+!Sync #1399
Apologies for the huge PR, but the bulk of the changes is basically search and replace so I hope it's not too difficult to review.