Bug 187866

Summary: Be more conservative with compositing layer creation when memory is low
Product: WebKit Reporter: Simon Fraser (smfr) <simon.fraser>
Component: New BugsAssignee: Simon Fraser (smfr) <simon.fraser>
Status: RESOLVED FIXED    
Severity: Normal CC: dino, ews-watchlist, koivisto, mjs, realdawei, rniwa, ryanhaddad, saam, simon.fraser, thorton, tsavell, zalan
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=188357
https://bugs.webkit.org/show_bug.cgi?id=188787
Attachments:
Description Flags
WIP Patch
none
Archive of layout-test-results from ews101 for mac-sierra
none
Archive of layout-test-results from ews104 for mac-sierra-wk2
none
Archive of layout-test-results from ews113 for mac-sierra
none
Patch zalan: review+

Description Simon Fraser (smfr) 2018-07-20 11:07:50 PDT
Be more conservative with compositing layer creation when memory is low
Comment 1 Simon Fraser (smfr) 2018-07-20 11:11:08 PDT
Created attachment 345464 [details]
WIP Patch
Comment 2 Simon Fraser (smfr) 2018-07-20 11:11:34 PDT
rdar://problem/42366345
Comment 3 EWS Watchlist 2018-07-20 12:01:45 PDT Comment hidden (obsolete)
Comment 4 EWS Watchlist 2018-07-20 12:01:47 PDT Comment hidden (obsolete)
Comment 5 EWS Watchlist 2018-07-20 12:04:22 PDT Comment hidden (obsolete)
Comment 6 EWS Watchlist 2018-07-20 12:04:23 PDT Comment hidden (obsolete)
Comment 7 EWS Watchlist 2018-07-20 12:07:48 PDT Comment hidden (obsolete)
Comment 8 EWS Watchlist 2018-07-20 12:07:49 PDT Comment hidden (obsolete)
Comment 9 Simon Fraser (smfr) 2018-07-25 21:53:06 PDT
Created attachment 345821 [details]
Patch
Comment 10 Dean Jackson 2018-07-25 21:56:29 PDT
Comment on attachment 345821 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=345821&action=review

> Source/WebCore/platform/graphics/transforms/Matrix3DTransformOperation.h:51
> +    bool isRepresentableIn2D() const final;

why not inline?
Comment 11 Simon Fraser (smfr) 2018-07-25 22:03:41 PDT
(In reply to Dean Jackson from comment #10)
> Comment on attachment 345821 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=345821&action=review
> 
> > Source/WebCore/platform/graphics/transforms/Matrix3DTransformOperation.h:51
> > +    bool isRepresentableIn2D() const final;
> 
> why not inline?

Virtual functions are never inlined by the compiler.
Comment 12 Maciej Stachowiak 2018-07-25 22:19:57 PDT
(In reply to Simon Fraser (smfr) from comment #11)
>
> Virtual functions are never inlined by the compiler.

They can be inlined if the compiler can statically prove the exact type, which sometimes it can (not sure if that applies in this case(.
Comment 13 Saam Barati 2018-07-25 23:26:35 PDT
(In reply to Maciej Stachowiak from comment #12)
> (In reply to Simon Fraser (smfr) from comment #11)
> >
> > Virtual functions are never inlined by the compiler.
> 
> They can be inlined if the compiler can statically prove the exact type,
> which sometimes it can (not sure if that applies in this case(.

Right. I think a common case where this happens a lot is when a class is marked as final
Comment 14 zalan 2018-07-26 19:30:25 PDT
Comment on attachment 345821 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=345821&action=review

> Source/WebCore/rendering/RenderLayerCompositor.cpp:2458
> +    if (!renderer.isCanvas())

is<RenderHTMLCanvas>

> Source/WebCore/rendering/RenderLayerCompositor.cpp:2461
> +    bool isCanvasLargeEnoughToForceCompositing = true;

auto?
Comment 15 Simon Fraser (smfr) 2018-07-27 08:41:12 PDT
+    switch (m_compositingPolicy) {
+    case CompositingPolicy::Normal:
+        return renderer.style().transform().has3DOperation();
+    case CompositingPolicy::Conservative:
+        // Continue to allow pages to avoid the very slow software filter path.
+        if (renderer.style().transform().has3DOperation() && renderer.hasFilter())
+            return true;
+        return !renderer.style().transform().isRepresentableIn2D();
+    }
Comment 16 Simon Fraser (smfr) 2018-07-27 15:20:51 PDT
https://trac.webkit.org/changeset/234330/webkit
Comment 17 Simon Fraser (smfr) 2018-07-28 08:46:26 PDT
I'm looking at the WK1 failures.
Comment 18 Simon Fraser (smfr) 2018-07-28 10:54:55 PDT
Followup in bug 188138.
Comment 19 Truitt Savell 2018-07-30 10:27:14 PDT
It looks like there are three tests on High Sierra WK1 that are continuing to fail consistently after https://trac.webkit.org/changeset/234330/webkit. The tests are flakey on other WK1 release platforms.

Tests:
legacy-animation-engine/compositing/backing/transform-transition-from-outside-view.html 
legacy-animation-engine/compositing/geometry/limit-layer-bounds-opacity-transition.html 
legacy-animation-engine/compositing/layer-creation/animation-overlap-with-children.html

Test History
https://webkit-test-results.webkit.org/dashboards/flakiness_dashboard.html#showAllRuns=true&tests=legacy-animation-engine%2Fcompositing%2Fbacking%2Ftransform-transition-from-outside-view.html%20legacy-animation-engine%2Fcompositing%2Fgeometry%2Flimit-layer-bounds-opacity-transition.html%20legacy-animation-engine%2Fcompositing%2Flayer-creation%2Fanimation-overlap-with-children.html

Text Diffs:
https://build.webkit.org/results/Apple%20High%20Sierra%20Release%20WK1%20(Tests)/r234363%20(7001)/legacy-animation-engine/compositing/backing/transform-transition-from-outside-view-diff.txt

https://build.webkit.org/results/Apple%20High%20Sierra%20Release%20WK1%20(Tests)/r234363%20(7001)/legacy-animation-engine/compositing/geometry/limit-layer-bounds-opacity-transition-diff.txt

https://build.webkit.org/results/Apple%20High%20Sierra%20Release%20WK1%20(Tests)/r234363%20(7001)/legacy-animation-engine/compositing/layer-creation/animation-overlap-with-children-diff.txt
Comment 20 Simon Fraser (smfr) 2018-07-30 11:09:08 PDT
I will look (these may be expected).
Comment 21 Truitt Savell 2018-08-02 10:30:33 PDT
Do we have any timeframe on when these tests will be fixed or an update on what's happening?
Comment 22 Antti Koivisto 2018-08-06 11:09:57 PDT
Comment on attachment 345821 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=345821&action=review

> Source/WebCore/page/Page.h:159
> +    Conservative, // Used in low memory situations.

"Conservative" is rather vague. How about just calling this CompositingPolicy::LowMemory? You can remove the comment too.
Comment 23 Truitt Savell 2018-09-04 16:19:48 PDT
I found that r234330 has also caused two tests to fail together:
inspector/layers/layer-tree-manager.html
inspector/layers/layers-anonymous.html

Test history:
https://webkit-test-results.webkit.org/dashboards/flakiness_dashboard.html#showAllRuns=true&tests=inspector%2Flayers%2Flayer-tree-manager.html%20inspector%2Flayers%2Flayers-anonymous.html

These two tests will fail together often on High Sierra Leaks and sometimes on other WK1 builds. This is all tracked in https://bugs.webkit.org/show_bug.cgi?id=188394

I was able to find a reliable reproduction method and it looks like https://trac.webkit.org/changeset/234330/webkit is at fault.