-
Notifications
You must be signed in to change notification settings - Fork 135
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
Cache local images into memory #1279
Conversation
e917a5a
to
e04b7ae
Compare
This introduces a cache for local image on macOS. There are no predefined limits set here (at least yet) since presumably we are loading a finite number of resources and we have the benefit of virtual memory swap on desktop so we don't really need to sweat a few extra megabytes of in-memory cache for images we know we'll need to repeatedly load. Local images don't use the shared RN image cache, and on macOS there's no automatic in-memory cache for local resources (other than the OS-level disk cache) so the `RCTImageFromLocalBundleAssetURL` function will synchronously access the disk on the main thread many times over during thread switching in Messenger Desktop. Added logging to confirmed cache works as expected in rn-tester, and instrumentation also confirms it.
e04b7ae
to
38a0e96
Compare
My general question with this change (and other related changes) is:
or
The former is easy to merge and justify, since presumably the React Native core team thought through the performance implications of caches / whatever change is being introduced. If it's the latter, I think we might have to think harder about upstreaming it and it's implications across other products. |
@Saadnajmi > It is nothing iOS is doing atm and I don't have all the insights to say whether the would benefit from it or not. We added this macOS only change to Messenger Desktop as we are loading quite a few assets from the application's mainBundle and this was one of the I/O accesses which profiling with Instruments marked as a potential performance bottleneck. What's your recommendation with this change? Change and upstream or abandon and keep only in our internal repo? |
Could we use the cache referenced in #1272 instead of making a new one? |
That would be ideal. It will require some refactoring. |
@Saadnajmi > I don't think there is a clear/easy/legit path to share the cache implementation with RCTImageCache. I still think this change is legit, I just added some tracing to Messenger Desktop and it seems we are loading assets from the application quite a lot > https://gist.github.com/christophpurrer/ec00f0a4daf68a6328cf61a6d40b49b5 W/o this in-memory cache we would always make a blocking I/O operation .... |
This introduces a cache for local image on macOS. There are no predefined limits set here (at least yet) since presumably we are loading a finite number of resources and we have the benefit of virtual memory swap on desktop so we don't really need to sweat a few extra megabytes of in-memory cache for images we know we'll need to repeatedly load. Local images don't use the shared RN image cache, and on macOS there's no automatic in-memory cache for local resources (other than the OS-level disk cache) so the `RCTImageFromLocalBundleAssetURL` function will synchronously access the disk on the main thread many times over during thread switching in Messenger Desktop. Added logging to confirmed cache works as expected in rn-tester, and instrumentation also confirms it. Co-authored-by: Scott Kyle <skyle@fb.com>
Please select one of the following
Summary
This introduces a cache for local image on macOS. There are no predefined limits set here (at least yet) since presumably we are loading a finite number of resources and we have the benefit of virtual memory swap on desktop so we don't really need to sweat a few extra megabytes of in-memory cache for images we know we'll need to repeatedly load.
Local images don't use the shared RN image cache, and on macOS there's no automatic in-memory cache for local resources (other than the OS-level disk cache) so the
RCTImageFromLocalBundleAssetURL
function will synchronously access the disk on the main thread many times when switching throw an app's UI or when reloading the app.Changelog
[macOS] [Added] - Cache local images into memory
Added logging to confirmed cache works as expected in rn-tester, and instrumentation also confirms it.
localImageCache.mov