Title: [270845] trunk/Source/WebCore
Revision
270845
Author
[email protected]
Date
2020-12-15 09:30:33 -0800 (Tue, 15 Dec 2020)

Log Message

REGRESSION(r268886): Page load time performance regression
https://bugs.webkit.org/show_bug.cgi?id=219677
<rdar://problem/71543823>

Reviewed by Darin Adler.

Optimize metadata fetching from images in ImageDecoderCG.
Instead of reading metadata separately for orientation and resolution,
use the partial metadata retrieved for orientation to figure out whether we need
extended metadata at all.

This will limit the expensive reading of extended metadata to images which might
have density size correction.

No new tests, this is an optimization covered by existing tests.

* platform/graphics/ImageDecoder.h:
(WebCore::ImageDecoder::frameDensityCorrectedSizeAtIndex const): Deleted.
* platform/graphics/ImageSource.cpp:
(WebCore::ImageSource::cacheMetadataAtIndex):
* platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h:
* platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm:
(WebCore::ImageDecoderAVFObjC::frameMetadataAtIndex const):
(WebCore::ImageDecoderAVFObjC::frameOrientationAtIndex const): Deleted.
* platform/graphics/gstreamer/ImageDecoderGStreamer.cpp:
(WebCore::ImageDecoderGStreamer::frameMetadataAtIndex const):
(WebCore::ImageDecoderGStreamer::frameOrientationAtIndex const): Deleted.
* platform/graphics/gstreamer/ImageDecoderGStreamer.h:
* platform/graphics/win/ImageDecoderDirect2D.cpp:
(WebCore::ImageDecoderDirect2D::frameOrientationAtIndex const): Deleted.
* platform/graphics/win/ImageDecoderDirect2D.h:
* platform/image-decoders/ScalableImageDecoder.h:
        Changed the signature to retrive metadata in one call

* platform/graphics/cg/ImageDecoderCG.cpp:
(WebCore::mayHaveDensityCorrectedSize):
(WebCore::densityCorrectedSizeFromProperties):
(WebCore::ImageDecoderCG::frameMetadataAtIndex const):
(WebCore::ImageDecoderCG::frameOrientationAtIndex const): Deleted.
(WebCore::ImageDecoderCG::frameDensityCorrectedSizeAtIndex const): Deleted.
* platform/graphics/cg/ImageDecoderCG.h:
        Figure out whether we need to read density based on partial metadata.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (270844 => 270845)


--- trunk/Source/WebCore/ChangeLog	2020-12-15 17:27:16 UTC (rev 270844)
+++ trunk/Source/WebCore/ChangeLog	2020-12-15 17:30:33 UTC (rev 270845)
@@ -1,3 +1,48 @@
+2020-12-15  Noam Rosenthal  <[email protected]>
+
+        REGRESSION(r268886): Page load time performance regression
+        https://bugs.webkit.org/show_bug.cgi?id=219677
+        <rdar://problem/71543823>
+
+        Reviewed by Darin Adler.
+
+        Optimize metadata fetching from images in ImageDecoderCG.
+        Instead of reading metadata separately for orientation and resolution,
+        use the partial metadata retrieved for orientation to figure out whether we need
+        extended metadata at all.
+
+        This will limit the expensive reading of extended metadata to images which might
+        have density size correction.
+
+        No new tests, this is an optimization covered by existing tests.
+
+        * platform/graphics/ImageDecoder.h:
+        (WebCore::ImageDecoder::frameDensityCorrectedSizeAtIndex const): Deleted.
+        * platform/graphics/ImageSource.cpp:
+        (WebCore::ImageSource::cacheMetadataAtIndex):
+        * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h:
+        * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm:
+        (WebCore::ImageDecoderAVFObjC::frameMetadataAtIndex const):
+        (WebCore::ImageDecoderAVFObjC::frameOrientationAtIndex const): Deleted.
+        * platform/graphics/gstreamer/ImageDecoderGStreamer.cpp:
+        (WebCore::ImageDecoderGStreamer::frameMetadataAtIndex const):
+        (WebCore::ImageDecoderGStreamer::frameOrientationAtIndex const): Deleted.
+        * platform/graphics/gstreamer/ImageDecoderGStreamer.h:
+        * platform/graphics/win/ImageDecoderDirect2D.cpp:
+        (WebCore::ImageDecoderDirect2D::frameOrientationAtIndex const): Deleted.
+        * platform/graphics/win/ImageDecoderDirect2D.h:
+        * platform/image-decoders/ScalableImageDecoder.h:
+                Changed the signature to retrive metadata in one call
+
+        * platform/graphics/cg/ImageDecoderCG.cpp:
+        (WebCore::mayHaveDensityCorrectedSize):
+        (WebCore::densityCorrectedSizeFromProperties):
+        (WebCore::ImageDecoderCG::frameMetadataAtIndex const):
+        (WebCore::ImageDecoderCG::frameOrientationAtIndex const): Deleted.
+        (WebCore::ImageDecoderCG::frameDensityCorrectedSizeAtIndex const): Deleted.
+        * platform/graphics/cg/ImageDecoderCG.h:
+                Figure out whether we need to read density based on partial metadata.
+
 2020-12-15  Youenn Fablet  <[email protected]>
 
         Make worker RTC insertable streams constructs controlled by webrtc insertable streams feature setting

Modified: trunk/Source/WebCore/platform/graphics/ImageDecoder.h (270844 => 270845)


--- trunk/Source/WebCore/platform/graphics/ImageDecoder.h	2020-12-15 17:27:16 UTC (rev 270844)
+++ trunk/Source/WebCore/platform/graphics/ImageDecoder.h	2020-12-15 17:30:33 UTC (rev 270845)
@@ -50,6 +50,12 @@
         Image,
         Video,
     };
+
+    struct FrameMetadata {
+        ImageOrientation orientation;
+        Optional<IntSize> densityCorrectedSize;
+    };
+
     static bool supportsMediaType(MediaType);
 
     virtual size_t bytesDecodedToDetermineProperties() const = 0;
@@ -66,8 +72,7 @@
 
     virtual IntSize frameSizeAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const = 0;
     virtual bool frameIsCompleteAtIndex(size_t) const = 0;
-    virtual ImageOrientation frameOrientationAtIndex(size_t) const = 0;
-    virtual Optional<IntSize> frameDensityCorrectedSizeAtIndex(size_t) const { return WTF::nullopt; }
+    virtual FrameMetadata frameMetadataAtIndex(size_t) const = 0;
 
     virtual Seconds frameDurationAtIndex(size_t) const = 0;
     virtual bool frameHasAlphaAtIndex(size_t) const = 0;

Modified: trunk/Source/WebCore/platform/graphics/ImageSource.cpp (270844 => 270845)


--- trunk/Source/WebCore/platform/graphics/ImageSource.cpp	2020-12-15 17:27:16 UTC (rev 270844)
+++ trunk/Source/WebCore/platform/graphics/ImageSource.cpp	2020-12-15 17:30:33 UTC (rev 270845)
@@ -271,8 +271,9 @@
     } else
         frame.m_size = m_decoder->frameSizeAtIndex(index, subsamplingLevel);
 
-    frame.m_orientation = m_decoder->frameOrientationAtIndex(index);
-    frame.m_densityCorrectedSize = m_decoder->frameDensityCorrectedSizeAtIndex(index);
+    auto metadata = m_decoder->frameMetadataAtIndex(index);
+    frame.m_orientation = metadata.orientation;
+    frame.m_densityCorrectedSize = metadata.densityCorrectedSize;
     frame.m_hasAlpha = m_decoder->frameHasAlphaAtIndex(index);
 
     if (repetitionCount())

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h (270844 => 270845)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h	2020-12-15 17:27:16 UTC (rev 270844)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h	2020-12-15 17:30:33 UTC (rev 270845)
@@ -75,7 +75,7 @@
 
     IntSize frameSizeAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const final;
     bool frameIsCompleteAtIndex(size_t) const final;
-    ImageOrientation frameOrientationAtIndex(size_t) const final;
+    ImageDecoder::FrameMetadata frameMetadataAtIndex(size_t) const final;
 
     Seconds frameDurationAtIndex(size_t) const final;
     bool frameHasAlphaAtIndex(size_t) const final;

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm (270844 => 270845)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm	2020-12-15 17:27:16 UTC (rev 270844)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm	2020-12-15 17:30:33 UTC (rev 270845)
@@ -513,9 +513,9 @@
     return sampleIsComplete(*sampleData);
 }
 
-ImageOrientation ImageDecoderAVFObjC::frameOrientationAtIndex(size_t) const
+ImageDecoder::FrameMetadata ImageDecoderAVFObjC::frameMetadataAtIndex(size_t) const
 {
-    return ImageOrientation::None;
+    return { };
 }
 
 Seconds ImageDecoderAVFObjC::frameDurationAtIndex(size_t index) const

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp (270844 => 270845)


--- trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp	2020-12-15 17:27:16 UTC (rev 270844)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp	2020-12-15 17:30:33 UTC (rev 270845)
@@ -174,6 +174,20 @@
     return ImageOrientation::fromEXIFValue(exifValue);
 }
 
+static bool mayHaveDensityCorrectedSize(CFDictionaryRef imageProperties)
+{
+    ASSERT(imageProperties);
+    auto resolutionXProperty = (CFNumberRef)CFDictionaryGetValue(imageProperties, kCGImagePropertyDPIWidth);
+    auto resolutionYProperty = (CFNumberRef)CFDictionaryGetValue(imageProperties, kCGImagePropertyDPIHeight);
+    if (!resolutionXProperty || !resolutionYProperty)
+        return false;
+
+    float resolutionX, resolutionY;
+    return CFNumberGetValue(resolutionXProperty, kCFNumberFloat32Type, &resolutionX)
+        && CFNumberGetValue(resolutionYProperty, kCFNumberFloat32Type, &resolutionY)
+        && (resolutionX != ImageResolution::DefaultResolution || resolutionY != ImageResolution::DefaultResolution);
+}
+
 static Optional<IntSize> densityCorrectedSizeFromProperties(CFDictionaryRef imageProperties)
 {
     ASSERT(imageProperties);
@@ -414,22 +428,21 @@
     return CGImageSourceGetStatusAtIndex(m_nativeDecoder.get(), index) == kCGImageStatusComplete;
 }
 
-ImageOrientation ImageDecoderCG::frameOrientationAtIndex(size_t index) const
+ImageDecoder::FrameMetadata ImageDecoderCG::frameMetadataAtIndex(size_t index) const
 {
     RetainPtr<CFDictionaryRef> properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), index, imageSourceOptions().get()));
     if (!properties)
-        return ImageOrientation::None;
+        return { };
     
-    return orientationFromProperties(properties.get());
-}
+    auto orientation = orientationFromProperties(properties.get());
+    if (!mayHaveDensityCorrectedSize(properties.get()))
+        return { orientation, WTF::nullopt };
 
-Optional<IntSize> ImageDecoderCG::frameDensityCorrectedSizeAtIndex(size_t index) const
-{
-    auto properties = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), index, createImageSourceMetadataOptions().get()));
-    if (!properties)
-        return WTF::nullopt;
+    auto propertiesWithMetadata = adoptCF(CGImageSourceCopyPropertiesAtIndex(m_nativeDecoder.get(), index, createImageSourceMetadataOptions().get()));
+    if (!propertiesWithMetadata)
+        return { orientation, WTF::nullopt };
     
-    return densityCorrectedSizeFromProperties(properties.get());
+    return { orientation, densityCorrectedSizeFromProperties(propertiesWithMetadata.get()) };
 }
 
 Seconds ImageDecoderCG::frameDurationAtIndex(size_t index) const

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h (270844 => 270845)


--- trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h	2020-12-15 17:27:16 UTC (rev 270844)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h	2020-12-15 17:30:33 UTC (rev 270845)
@@ -54,8 +54,7 @@
 
     IntSize frameSizeAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const final;
     bool frameIsCompleteAtIndex(size_t) const final;
-    ImageOrientation frameOrientationAtIndex(size_t) const final;
-    Optional<IntSize> frameDensityCorrectedSizeAtIndex(size_t) const final;
+    ImageDecoder::FrameMetadata frameMetadataAtIndex(size_t) const final;
 
     Seconds frameDurationAtIndex(size_t) const final;
     bool frameHasAlphaAtIndex(size_t) const final;

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.cpp (270844 => 270845)


--- trunk/Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.cpp	2020-12-15 17:27:16 UTC (rev 270844)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.cpp	2020-12-15 17:30:33 UTC (rev 270845)
@@ -149,10 +149,10 @@
     return { };
 }
 
-ImageOrientation ImageDecoderGStreamer::frameOrientationAtIndex(size_t) const
+ImageDecoder::FrameMetadata ImageDecoderGStreamer::frameMetadataAtIndex(size_t) const
 {
     notImplemented();
-    return ImageOrientation::None;
+    return { };
 }
 
 Seconds ImageDecoderGStreamer::frameDurationAtIndex(size_t index) const

Modified: trunk/Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.h (270844 => 270845)


--- trunk/Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.h	2020-12-15 17:27:16 UTC (rev 270844)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/ImageDecoderGStreamer.h	2020-12-15 17:30:33 UTC (rev 270845)
@@ -60,7 +60,7 @@
 
     IntSize frameSizeAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const final { return size(); }
     bool frameIsCompleteAtIndex(size_t index) const final { return sampleAtIndex(index); }
-    ImageOrientation frameOrientationAtIndex(size_t) const final;
+    ImageDecoder::FrameMetadata frameMetadataAtIndex(size_t) const final;
 
     Seconds frameDurationAtIndex(size_t) const final;
     bool frameHasAlphaAtIndex(size_t) const final;

Modified: trunk/Source/WebCore/platform/graphics/win/ImageDecoderDirect2D.cpp (270844 => 270845)


--- trunk/Source/WebCore/platform/graphics/win/ImageDecoderDirect2D.cpp	2020-12-15 17:27:16 UTC (rev 270844)
+++ trunk/Source/WebCore/platform/graphics/win/ImageDecoderDirect2D.cpp	2020-12-15 17:30:33 UTC (rev 270845)
@@ -155,29 +155,28 @@
     HRESULT hr = m_nativeDecoder->GetFrame(index, &frame);
     return SUCCEEDED(hr);
 }
-
-ImageOrientation ImageDecoderDirect2D::frameOrientationAtIndex(size_t index) const
+ImageDecoder::FrameMetadata ImageDecoderDirect2D::frameMetadataAtIndex(size_t) const final;
 {
     if (!m_nativeDecoder)
-        return ImageOrientation::None;
+        return { };
 
     COMPtr<IWICBitmapFrameDecode> frame;
     HRESULT hr = m_nativeDecoder->GetFrame(index, &frame);
     if (!SUCCEEDED(hr))
-        return ImageOrientation::None;
+        return { };
 
     COMPtr<IWICMetadataQueryReader> metadata;
     hr = frame->GetMetadataQueryReader(&metadata);
     if (!SUCCEEDED(hr))
-        return ImageOrientation::None;
+        return { };
 
     PROPVARIANT value;
     PropVariantInit(&value);
     hr = metadata->GetMetadataByName(L"System.Photo.Orientation", &value);
     if (SUCCEEDED(hr))
-        return ImageOrientation(static_cast<ImageOrientation::Orientation>(value.uiVal));
+        return { ImageOrientation(static_cast<ImageOrientation::Orientation>(value.uiVal)), WTF::nullopt };
 
-    return ImageOrientation::None;
+    return { };
 }
 
 Seconds ImageDecoderDirect2D::frameDurationAtIndex(size_t index) const

Modified: trunk/Source/WebCore/platform/graphics/win/ImageDecoderDirect2D.h (270844 => 270845)


--- trunk/Source/WebCore/platform/graphics/win/ImageDecoderDirect2D.h	2020-12-15 17:27:16 UTC (rev 270844)
+++ trunk/Source/WebCore/platform/graphics/win/ImageDecoderDirect2D.h	2020-12-15 17:30:33 UTC (rev 270845)
@@ -63,7 +63,7 @@
 
     IntSize frameSizeAtIndex(size_t, SubsamplingLevel = SubsamplingLevel::Default) const final;
     bool frameIsCompleteAtIndex(size_t) const final;
-    ImageOrientation frameOrientationAtIndex(size_t) const final;
+    ImageDecoder::FrameMetadata frameMetadataAtIndex(size_t) const final;
 
     Seconds frameDurationAtIndex(size_t) const final;
     bool frameHasAlphaAtIndex(size_t) const final;

Modified: trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.h (270844 => 270845)


--- trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.h	2020-12-15 17:27:16 UTC (rev 270844)
+++ trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.h	2020-12-15 17:30:33 UTC (rev 270845)
@@ -149,8 +149,7 @@
     void setIgnoreGammaAndColorProfile(bool flag) { m_ignoreGammaAndColorProfile = flag; }
     bool ignoresGammaAndColorProfile() const { return m_ignoreGammaAndColorProfile; }
 
-    ImageOrientation frameOrientationAtIndex(size_t) const override { return m_orientation; }
-    Optional<IntSize> frameDensityCorrectedSizeAtIndex(size_t) const override { return m_densityCorrectedSize; }
+    ImageDecoder::FrameMetadata frameMetadataAtIndex(size_t) const override { return { m_orientation, m_densityCorrectedSize }; }
 
     bool frameAllowSubsamplingAtIndex(size_t) const override { return false; }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to