Prune old egui memory data when reaching some limit #3299
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously egui would just accumulate state over time, growing its memory more and more if the user had unique
Id
s with persisted state, e.g. a lot ofCollapsingHeader
s orWindow
s with different names. This leads to slow load and save ofeframe
apps with persistence.With this PR egui will now forget the oldest data of each type that hasn't been read in a while. That is, if you load and save your app state many times, egui will eventually drop the thing that never been read.
The limit can be set with
egui_ctx.memory_mut(|m| m.data.set_max_bytes_per_type(1_000_000));
The default is 256 kiB per type. For reference, a
CollapsingHeader
takes around 200 bytes to store, so that's over a thousand different collapsing headers in your application.