<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>216701</bug_id>
          
          <creation_ts>2020-09-18 09:30:36 -0700</creation_ts>
          <short_desc>WebKit incorrectly composites hundreds of elements when using position: relative</short_desc>
          <delta_ts>2021-01-15 05:36:07 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Compositing</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Liam DeBeasi">ldebeasi</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>niklasmerz</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zalan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1689817</commentid>
    <comment_count>0</comment_count>
      <attachid>409137</attachid>
    <who name="Liam DeBeasi">ldebeasi</who>
    <bug_when>2020-09-18 09:30:36 -0700</bug_when>
    <thetext>Created attachment 409137
Code Reproduction

When an element with a 3d transform is placed in the same scrollable container as elements with position: relative, the elements with position: relative are incorrectly composited.

The Layers pane in Safari claims this is due to the relative elements overlapping the transformed element, even when they are not. Removing position: relative from these elements resolves the issue. Additionally, using a 2d transform instead of a 3d transform resolves the issue as well.

This issue was observed in STP 113, but can be reproduced in Safari 13 as well. Additionally, this issue can be reproduced on both macOS and iOS.

Steps to reproduce:

1. Open the attached code reproduction in Safari.
2. Open dev tools and navigate to the &quot;Layers&quot; tab. The default layout has a div with a 3d transform and a list of divs with position: relative. You should notice that there are over 150 layers rendered.
3. Uncheck the &quot;Use 3D Transform&quot; checkbox. This will use a 2d transform instead. You should observe that there are only 2 layers now.
4. Recheck the &quot;Use 3D Transform&quot; checkbox.
5. Uncheck the &quot;Use div with position: relative&quot; checkbox. This will remove position: relative from the list items. You should observe that there are only 3 layers now.

When selecting a list element layer, Safari indicates that it was composited because it &quot;overlaps other compositing elements&quot;. The element is overlapping the scrollable container which is composited; however, this additional compositing only happens when the element with a 3d transform is present. In this case, no list item overlaps the element with 3d transform.

There are 2 reasons why I think this is a bug:

1. This behavior does not happen in Chrome. Chrome never composites the list items.
2. Given a scrollable list, this issue significantly degrades scrolling performance. It is most noticeable on an iPad.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1690366</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2020-09-21 11:48:35 -0700</bug_when>
    <thetext>&lt;rdar://problem/69317469&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1690870</commentid>
    <comment_count>2</comment_count>
      <attachid>409404</attachid>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2020-09-22 15:05:03 -0700</bug_when>
    <thetext>Created attachment 409404
Better testcase</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1690871</commentid>
    <comment_count>3</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2020-09-22 15:07:10 -0700</bug_when>
    <thetext>The relative-positioned elements end up in layers because the scroller is not a CSS stacking context, so conceptually the relative elements render as siblings (not descendants). There&apos;s an optimization to avoid this (layer backing sharing) but the transformed element defeats it.

If you test with the transformed element in the middle of the list you should see no layers for relative elements that come before it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1690917</commentid>
    <comment_count>4</comment_count>
    <who name="Liam DeBeasi">ldebeasi</who>
    <bug_when>2020-09-22 15:57:06 -0700</bug_when>
    <thetext>Ah ok that&apos;s interesting. Thanks for the additional test case -- that clarifies things a bit for me. Would this be another scenario where an optimization could be made by WebKit, or would you consider this to be expected behavior?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1690919</commentid>
    <comment_count>5</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2020-09-22 15:58:13 -0700</bug_when>
    <thetext>It&apos;s obviously valuable to optimize but hard to fix given webkit&apos;s current compositing architecture.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1690923</commentid>
    <comment_count>6</comment_count>
    <who name="Liam DeBeasi">ldebeasi</who>
    <bug_when>2020-09-22 16:04:30 -0700</bug_when>
    <thetext>That&apos;s fair. I can dance around the issue for now by using 2d transforms in affected components in Ionic Framework.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1690930</commentid>
    <comment_count>7</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2020-09-22 16:34:12 -0700</bug_when>
    <thetext>Making the scroller a stacking context (will-change: transform or position and z-index) should eliminate this entirely.

Maybe a z-index &gt; 0 on the transformed item too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1691946</commentid>
    <comment_count>8</comment_count>
    <who name="Liam DeBeasi">ldebeasi</who>
    <bug_when>2020-09-25 10:58:06 -0700</bug_when>
    <thetext>Adding will-change: transform to the scrolling element solved it for us. Thanks for the suggestion!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1706433</commentid>
    <comment_count>9</comment_count>
    <who name="Liam DeBeasi">ldebeasi</who>
    <bug_when>2020-11-11 06:13:51 -0800</bug_when>
    <thetext>Wanted to add a note for anyone who stumbles upon this and uses will-change: transform as a workaround: Make sure you only target WebKit as using will-change: transform on a scrollable element will break any position: fixed elements in the scrollable element in Chromium browsers.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1706436</commentid>
    <comment_count>10</comment_count>
    <who name="Liam DeBeasi">ldebeasi</who>
    <bug_when>2020-11-11 06:22:55 -0800</bug_when>
    <thetext>Actually it looks like this position: fixed behavior is correct according to https://bugs.chromium.org/p/chromium/issues/detail?id=413456. There is an open WebKit issue to address this behavior: https://bugs.webkit.org/show_bug.cgi?id=167600

will-change: transform on a scrollable element is probably not a good solution here, but I will look into other workarounds.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1706507</commentid>
    <comment_count>11</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2020-11-11 10:14:42 -0800</bug_when>
    <thetext>Try &quot;position: relative; z-index: 0&quot; on the scroller.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1706991</commentid>
    <comment_count>12</comment_count>
    <who name="Liam DeBeasi">ldebeasi</who>
    <bug_when>2020-11-12 13:05:19 -0800</bug_when>
    <thetext>That seems to work, thank you!</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>409137</attachid>
            <date>2020-09-18 09:30:36 -0700</date>
            <delta_ts>2020-09-18 09:30:36 -0700</delta_ts>
            <desc>Code Reproduction</desc>
            <filename>index.html</filename>
            <type>text/html</type>
            <size>1752</size>
            <attacher name="Liam DeBeasi">ldebeasi</attacher>
            
              <data encoding="base64">PGh0bWw+CiAgPGhlYWQ+CiAgICA8bWV0YSBuYW1lPSJ2aWV3cG9ydCIKICAgIGNvbnRlbnQ9Indp
ZHRoPWRldmljZS13aWR0aCwgaW5pdGlhbC1zY2FsZT0xLjAsIG1pbmltdW0tc2NhbGU9MS4wLCBt
YXhpbXVtLXNjYWxlPTEuMCwgdXNlci1zY2FsYWJsZT1ubyI+CiAgICA8c3R5bGU+CiAgICAgIC5w
b3NpdGlvbiB7CiAgICAgICAgcG9zaXRpb246IHJlbGF0aXZlOwogICAgICB9CiAgICAKICAgICAg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gdHJhbnNmb3JtID0gZG9jdW1lbnQucXVlcnlTZWxlY3RvcignLnRy
YW5zZm9ybScpOwogICAgbGV0IGxpc3QgPSBkb2N1bWVudC5xdWVyeVNlbGVjdG9yKCcubGlzdC13
cmFwcGVyJyk7CgogICAgY29uc3Qgc2V0VHJhbnNmb3JtID0gKCkgPT4gewogICAgICBjb25zdCB0
cmFuc2Zvcm1WYWx1ZSA9ICh0cmFuc2Zvcm1DaGVja2JveC5jaGVja2VkKSA/ICd0cmFuc2xhdGUz
ZCgwLCAwLCAwKScgOiAndHJhbnNsYXRlKDAsIDApJzsKICAgICAgdHJhbnNmb3JtLnN0eWxlLnRy
YW5zZm9ybSA9IHRyYW5zZm9ybVZhbHVlOwogICAgfQogICAgCiAgICBjb25zdCBzZXRDb21wb25l
bnRUeXBlID0gKCkgPT4gewogICAgICBjb25zdCB1c2VDbGFzcyA9IGNvbXBvbmVudENoZWNrYm94
LmNoZWNrZWQ7CiAgICAgIGxldCBzdHJpbmcgPSAodXNlQ2xhc3MpID8gYDxkaXYgY2xhc3M9InBv
c2l0aW9uIj5IZWxsbyBXb3JsZDwvZGl2PmAgOiAnPGRpdj5IZWxsbyBXb3JsZDwvZGl2Pic7CiAg
ICAgIGxldCBsaXN0U3RyaW5nID0gJyc7CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgMTUwOyBp
KyspIHsKICAgICAgICBsaXN0U3RyaW5nICs9IHN0cmluZzsKICAgICAgfQogICAgCiAgICAgIGxp
c3QuaW5uZXJIVE1MID0gbGlzdFN0cmluZzsKICAgIH0KICAKICAgIHNldFRyYW5zZm9ybSgpOwog
ICAgc2V0Q29tcG9uZW50VHlwZSgpOwogIDwvc2NyaXB0Pgo8L2h0bWw+
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>409404</attachid>
            <date>2020-09-22 15:05:03 -0700</date>
            <delta_ts>2020-09-22 15:05:03 -0700</delta_ts>
            <desc>Better testcase</desc>
            <filename>transform-triggered-layers-in-scroller.html</filename>
            <type>text/html</type>
            <size>1918</size>
            <attacher name="Simon Fraser (smfr)">simon.fraser</attacher>
            
              <data encoding="base64">PGh0bWw+CiAgPGhlYWQ+CiAgICA8bWV0YSBuYW1lPSJ2aWV3cG9ydCIKICAgIGNvbnRlbnQ9Indp
ZHRoPWRldmljZS13aWR0aCwgaW5pdGlhbC1zY2FsZT0xLjAsIG1pbmltdW0tc2NhbGU9MS4wLCBt
YXhpbXVtLXNjYWxlPTEuMCwgdXNlci1zY2FsYWJsZT1ubyI+CiAgICA8c3R5bGU+CiAgICAgIC5p
bm5lci1zY3JvbGwgewogICAgICAgIG92ZXJmbG93LXk6IHNjcm9sbDsKICAgICAgICBtYXJnaW46
IDEwcHg7CiAgICAgICAgaGVpZ2h0OiA0MDBweDsKICAgICAgICB3aWR0aDogNDAwcHg7CiAgICAg
ICAgYm9yZGVyOiAxcHggc29saWQgYmxhY2s7CiAgICAgIH0KICAgICAgCiAgICAgIC5ib3ggewog
ICAgICAgICAgaGVpZ2h0OiAxMDBweDsKICAgICAgICAgIG1hcmdpbjogMTBweDsKICAgICAgICAg
IHBhZGRpbmc6IDEwcHg7CiAgICAgIH0KCiAgICAgIC5wb3NpdGlvbmVkIHsKICAgICAgICBwb3Np
dGlvbjogcmVsYXRpdmU7CiAgICAgIH0KICAgICAgPC9zdHlsZT4KICA8L2hlYWQ+CiAgPGJvZHk+
CgogICAgICAgIDxpbnB1dCB0eXBlPSJjaGVja2JveCIgaWQ9InRyYW5zZm9ybSIgdmFsdWU9IjNk
IiBvbmNoYW5nZT0ic2V0VHJhbnNmb3JtKCkiIGNoZWNrZWQ+CiAgICAgICAgPGxhYmVsIGZvcj0i
dHJhbnNmb3JtIj5Vc2UgM0QgVHJhbnNmb3JtPC9sYWJlbD4KCiAgICAgICAgPGJyLz4KICAgICAg
ICAKICAgICAgICA8aW5wdXQgdHlwZT0iY2hlY2tib3giIGlkPSJjb21wb25lbnQiIHZhbHVlPS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