Use soft references for file reference data #1146
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.
Use soft references to hold on to file data loaded from file references. This should allow images that are loaded to be cached as long as possible, but freed if available memory gets low.
Pros: If you have lots of huge logos, they should be loaded, scaled down, and only the scaled versions used; the originals will be kept in memory in case we need other resolutions, but thrown out if memory gets low. Memory use will be much better when images are only used once / at one resolution.
Cons: If we have presentations that use different resolutions of an image in sequence, there will be less caching and initial (re)load for each presentation will be slower.
I tested with a similar change several years ago and the results weren't great: especially on HDDs the performance of loading images was slow and files weren't huge so the best tradeoff for smooth UI was almost always 'just use a bit more memory'. With faster SSDs and CPU but photos often > 4k the balance seems to have shifted: with this change I see images being reloaded that would have been cached before, but memory use is more consistent / less spikes, and the cache doesn't grow indefinitely (until all file references have been loaded - which is potentially a lot).
Should help with #1133 and avoid related out of memory errors.