Skip to content

Speed up eframe state storage#3353

Merged
emilk merged 1 commit intoemilk:masterfrom
sebbert:file-storage-bufwriter
Sep 18, 2023
Merged

Speed up eframe state storage#3353
emilk merged 1 commit intoemilk:masterfrom
sebbert:file-storage-bufwriter

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
@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