Skip to content

Commit

Permalink
Cache local images into memory (microsoft#1279)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
2 people authored and Shawn Dempsey committed Feb 13, 2023
1 parent d8dfc86 commit c920685
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions React/Base/RCTUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#import "RCTAssert.h"
#import "RCTLog.h"

static const NSUInteger RCTMaxCachableImageCount = 100;

NSString *const RCTErrorUnspecified = @"EUNSPECIFIED";

// Returns the Path of Home directory
Expand Down

0 comments on commit c920685

Please sign in to comment.