Skip to content
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

Speed up eframe state storage #3353

Merged
merged 1 commit into from
Sep 18, 2023
Merged

Conversation

sebbert
Copy link
Contributor

@sebbert sebbert commented Sep 18, 2023

When exiting my application, it would freeze for around a minute waiting to finish writing ca. 40MB to file storage. Some quick profiling revealed that it was spending all that time in File::write, presumably making a large number of system calls writing tiny amounts of data at a time. We can avoid this by buffering writes using a BufWriter, just like we already do with BufReader.

With this change, my application takes around 1-2 seconds to exit, with the majority of that time spent serializing ron. I'm sure there are further potential performance improvements there, but this is already an order of magnitude or two better.

I also fixed the call to log::warn!, which was using incorrect formatting syntax and not including the error message.

I've run scripts/check.sh, all checks passed.

Closes https://github.com/emilk/egui/issues/THE_RELEVANT_ISSUE.

I didn't raise an issue first, since this is such a small change. Let me know if you want me to create one.

When exiting my application, it would freeze for around a minute waiting to finish writing ca. 40MB to file storage.
Some quick profiling revealed that it was spending all that time in `File::write`,
presumably making a large number of system calls writing tiny amounts of data at a time.
We can avoid this by buffering writes using a `BufWriter`, just like we already do with `BufReader`.

With this change, my application takes around 1-2 seconds to exit, with the majority of that time spent serializing `ron`.
I'm sure there are further potential performance improvements there, but this is already an order of magnitude or two better.

I also fixed the call to `log::warn!`, which was using incorrect formatting syntax and not including the error message.
Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, great find! Thanks

@emilk emilk added the eframe Relates to epi and eframe label Sep 18, 2023
@emilk emilk merged commit 433d1fc into emilk:master Sep 18, 2023
18 of 19 checks passed
@sebbert sebbert deleted the file-storage-bufwriter branch September 18, 2023 18:25
@emilk emilk changed the title file_storage: Wrap File in BufWriter Optimize eframe state storage Sep 27, 2023
@emilk emilk changed the title Optimize eframe state storage Speed up eframe state storage Sep 27, 2023
@emilk emilk added the performance Lower CPU/GPU usage (optimize) label Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eframe Relates to epi and eframe performance Lower CPU/GPU usage (optimize)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants