From 3bbfab545aed9cb8f91f260d3db7bbeeb2aef34b Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Fri, 25 Sep 2015 02:26:25 -0700 Subject: [PATCH] Log when RCTImageView reloads and when assets are scaled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../CameraRoll/RCTAssetsLibraryImageLoader.m | 15 +++++++++++++++ Libraries/Image/RCTImageView.m | 2 ++ 2 files changed, 17 insertions(+) diff --git a/Libraries/CameraRoll/RCTAssetsLibraryImageLoader.m b/Libraries/CameraRoll/RCTAssetsLibraryImageLoader.m index 0e84ba503..331fd5bb9 100644 --- a/Libraries/CameraRoll/RCTAssetsLibraryImageLoader.m +++ b/Libraries/CameraRoll/RCTAssetsLibraryImageLoader.m @@ -69,6 +69,21 @@ RCT_EXPORT_MODULE() BOOL useMaximumSize = CGSizeEqualToSize(size, CGSizeZero); ALAssetRepresentation *representation = [asset defaultRepresentation]; + #if RCT_DEV + CGSize sizeBeingLoaded = size; + if (useMaximumSize) { + CGSize pointSize = representation.dimensions; + sizeBeingLoaded = CGSizeMake(pointSize.width * representation.scale, pointSize.height * representation.scale); + } + + CGSize screenSize = UIScreen.mainScreen.nativeBounds.size; + CGFloat maximumPixelDimension = fmax(screenSize.width, screenSize.height); + + if (sizeBeingLoaded.width > maximumPixelDimension || sizeBeingLoaded.height > maximumPixelDimension) { + RCTLogInfo(@"[PERF ASSETS] Loading %@ at size %@, which is larger than screen size %@", representation.filename, NSStringFromCGSize(sizeBeingLoaded), NSStringFromCGSize(screenSize)); + } + #endif + UIImage *image; NSError *error = nil; if (useMaximumSize) { diff --git a/Libraries/Image/RCTImageView.m b/Libraries/Image/RCTImageView.m index 52742cb1c..b37c897be 100644 --- a/Libraries/Image/RCTImageView.m +++ b/Libraries/Image/RCTImageView.m @@ -218,6 +218,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) if (RCTShouldReloadImageForSizeChange(imageSize, idealSize)) { if (RCTShouldReloadImageForSizeChange(_targetSize, idealSize)) { + RCTLogInfo(@"[PERF IMAGEVIEW] Reloading image %@ as size %@", _src, NSStringFromCGSize(idealSize)); + // If the existing image or an image being loaded are not the right size, reload the asset in case there is a // better size available. _targetSize = idealSize;