Skip to content

Commit 3bbfab5

Browse files
jspahrsummersfacebook-github-bot-9
authored andcommitted
Log when RCTImageView reloads and when assets are scaled
Summary: This sort of logging helped me identify issues with reloading images too frequently (and for trivial reasons), so leaving it in might be useful for future optimization work, or for anyone building apps using these components. @​public Reviewed By: @alexeylang Differential Revision: D2475613
1 parent 9293e54 commit 3bbfab5

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

Libraries/CameraRoll/RCTAssetsLibraryImageLoader.m

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ - (RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL size:(CGSiz
6969
BOOL useMaximumSize = CGSizeEqualToSize(size, CGSizeZero);
7070
ALAssetRepresentation *representation = [asset defaultRepresentation];
7171

72+
#if RCT_DEV
73+
CGSize sizeBeingLoaded = size;
74+
if (useMaximumSize) {
75+
CGSize pointSize = representation.dimensions;
76+
sizeBeingLoaded = CGSizeMake(pointSize.width * representation.scale, pointSize.height * representation.scale);
77+
}
78+
79+
CGSize screenSize = UIScreen.mainScreen.nativeBounds.size;
80+
CGFloat maximumPixelDimension = fmax(screenSize.width, screenSize.height);
81+
82+
if (sizeBeingLoaded.width > maximumPixelDimension || sizeBeingLoaded.height > maximumPixelDimension) {
83+
RCTLogInfo(@"[PERF ASSETS] Loading %@ at size %@, which is larger than screen size %@", representation.filename, NSStringFromCGSize(sizeBeingLoaded), NSStringFromCGSize(screenSize));
84+
}
85+
#endif
86+
7287
UIImage *image;
7388
NSError *error = nil;
7489
if (useMaximumSize) {

Libraries/Image/RCTImageView.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ - (void)reactSetFrame:(CGRect)frame
218218

219219
if (RCTShouldReloadImageForSizeChange(imageSize, idealSize)) {
220220
if (RCTShouldReloadImageForSizeChange(_targetSize, idealSize)) {
221+
RCTLogInfo(@"[PERF IMAGEVIEW] Reloading image %@ as size %@", _src, NSStringFromCGSize(idealSize));
222+
221223
// If the existing image or an image being loaded are not the right size, reload the asset in case there is a
222224
// better size available.
223225
_targetSize = idealSize;

0 commit comments

Comments
 (0)