<?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>226330</bug_id>
          
          <creation_ts>2021-05-27 06:55:04 -0700</creation_ts>
          <short_desc>Double clicking on very large but visually empty DOM can be slow due to selection computation</short_desc>
          <delta_ts>2022-06-28 01:47:24 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>CSS</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>emilio</cc>
    
    <cc>koivisto</cc>
    
    <cc>marc</cc>
    
    <cc>phil.moore</cc>
    
    <cc>rniwa</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>1764316</commentid>
    <comment_count>0</comment_count>
      <attachid>429874</attachid>
    <who name="Liam DeBeasi">ldebeasi</who>
    <bug_when>2021-05-27 06:55:04 -0700</bug_when>
    <thetext>Created attachment 429874
Code reproduction

This is a continuation of https://bugs.webkit.org/show_bug.cgi?id=222187 which was partially resolved in STP 125. When using Web Components inside of the Shadow DOM that have CSS Variables set on the host, there is a significant delay in response to clicks/touches. There were fixes in STP 125 that improved this issue, but I am still able to reproduce this issue in other ways.

Steps to reproduce:

1. Open code reproduction in STP 125.
2. Quickly click multiple times on the &quot;Click Me&quot; label (not the checkbox) and you should see Safari freeze up.
3. If you repeat step 2 while taking a Timeline sample, you should see the CPU usage spike significantly. In my tests I clicked about 4-5 times and saw the CPU spike to over 80% on average. 

Expected Behavior:

I would expect Safari to not freeze up when quickly clicking the label multiple times.

Actual Behavior:

Safari freezes up when quickly clicking the label multiple times.

Other Info:

- As noted in https://bugs.webkit.org/show_bug.cgi?id=222187, the example I used is inherently heavy in shadow trees to emphasize the issue. Please see https://github.com/ionic-team/ionic-framework/issues/22951 for more &quot;real world&quot; examples of this impacting applications.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1764619</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2021-05-27 18:21:22 -0700</bug_when>
    <thetext>Thank you for the report!

Is the performance still worse than pre-iOS 14, or is this about further optimization opportunities? Does this appear to be worse in Safari (STP) than in other browsers?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1764847</commentid>
    <comment_count>2</comment_count>
    <who name="Liam DeBeasi">ldebeasi</who>
    <bug_when>2021-05-28 11:37:16 -0700</bug_when>
    <thetext>The performance of single clicking the checkbox in my example is good after https://bugs.webkit.org/show_bug.cgi?id=222187, but multiple clicks is where there are still issues. When doing multiple clicks, the performance in STP 125 is worse than in other browsers and worse than in pre-iOS/Safari 14.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1766374</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2021-06-03 06:56:16 -0700</bug_when>
    <thetext>&lt;rdar://problem/78813010&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1772626</commentid>
    <comment_count>4</comment_count>
    <who name="">marc</who>
    <bug_when>2021-06-25 05:30:12 -0700</bug_when>
    <thetext>Hi guys, just wondered if there&apos;s been any movement on this?

Thanks,</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1876997</commentid>
    <comment_count>5</comment_count>
    <who name="Philip Moore">phil.moore</who>
    <bug_when>2022-06-21 10:34:25 -0700</bug_when>
    <thetext>Be great to understand when this might get resolved, we’ve got a production app https://apps.apple.com/gb/app/mydrivetime-companion-app/id950711705 that’s being heavily impacted and stopping us from releasing a major update that our users need.

Many thanks</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1877248</commentid>
    <comment_count>6</comment_count>
    <who name="">marc</who>
    <bug_when>2022-06-22 01:10:26 -0700</bug_when>
    <thetext>(In reply to Philip Moore from comment #5)
&gt; Be great to understand when this might get resolved, we’ve got a production
&gt; app https://apps.apple.com/gb/app/mydrivetime-companion-app/id950711705
&gt; that’s being heavily impacted and stopping us from releasing a major update
&gt; that our users need.
&gt; 
&gt; Many thanks

Hi Philip, by the fact this issue hasn&apos;t really moved forwards in over a year, I don&apos;t think anyone at webkit really cares about it. We had exactly the same issue last year and they&apos;ve essentially ignored this thread. It seems we are expected to have write overly exuberant lazy loading component code to over come an issue that shouldn&apos;t be a problem to start with, as any other browser/device works fine, it&apos;s just anything Apple.

This is ridiculous, if I have an issue open for more than a 2 weeks my bosses complain, I think I would have been fired if I had a bug open for over a year.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1877293</commentid>
    <comment_count>7</comment_count>
    <who name="Liam DeBeasi">ldebeasi</who>
    <bug_when>2022-06-22 08:22:11 -0700</bug_when>
    <thetext>Hey everyone,

While I know it is frustrating to not have your ticket resolved quickly, comments like the one in https://bugs.webkit.org/show_bug.cgi?id=226330#c6 are not super constructive.

Instead, comments that provide context around the impact of a bug (such as the comment in https://bugs.webkit.org/show_bug.cgi?id=226330#c5) are incredibly helpful. This context can be used to better prioritize issues.

Having worked on a large open source project (though not as large as a browser engine), I can say that it is not always possible to reply to every single issue/comment. Let’s try to keep this thread constructive and focus on identifying the impact this bug has on production apps/websites.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1877554</commentid>
    <comment_count>8</comment_count>
    <who name="alan">zalan</who>
    <bug_when>2022-06-22 21:43:21 -0700</bug_when>
    <thetext>I did a bit of profiling on this and it looks like (after the invalidation fix), this is simply about iterating over that massive amount of content when computing selection boundary. 
The following, simple markup triggers this issue:

&lt;body&gt;
Click Me&lt;input type=&quot;checkbox&quot;&gt;&lt;br&gt;
    &lt;span&gt;&lt;/span&gt;
    &lt;span&gt;&lt;/span&gt;
    &lt;span&gt;&lt;/span&gt;
    &lt;span&gt;&lt;/span&gt;
    &lt;span&gt;&lt;/span&gt;
repeat it for a few thousands of times
&lt;/body&gt;

It looks like VisibleSelection needs a more efficient way to figure out the selection end on user action (or in general for that matter).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1877657</commentid>
    <comment_count>9</comment_count>
    <who name="Antti Koivisto">koivisto</who>
    <bug_when>2022-06-23 09:03:13 -0700</bug_when>
    <thetext>Note that you can work around this issue by preventing the selection with &quot;user-select:none&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1877677</commentid>
    <comment_count>10</comment_count>
    <who name="alan">zalan</who>
    <bug_when>2022-06-23 10:03:31 -0700</bug_when>
    <thetext>(In reply to zalan from comment #8)
&gt; I did a bit of profiling on this and it looks like (after the invalidation
&gt; fix), this is simply about iterating over that massive amount of content
&gt; when computing selection boundary. 
&gt; The following, simple markup triggers this issue:
&gt; 
&gt; &lt;body&gt;
&gt; Click Me&lt;input type=&quot;checkbox&quot;&gt;&lt;br&gt;
&gt;     &lt;span&gt;&lt;/span&gt;
&gt;     &lt;span&gt;&lt;/span&gt;
&gt;     &lt;span&gt;&lt;/span&gt;
&gt;     &lt;span&gt;&lt;/span&gt;
&gt;     &lt;span&gt;&lt;/span&gt;
&gt; repeat it for a few thousands of times
&gt; &lt;/body&gt;
&gt; 
&gt; It looks like VisibleSelection needs a more efficient way to figure out the
&gt; selection end on user action (or in general for that matter).
However if there&apos;s any &quot;non-visually empty&quot; content somewhere e.g.

&lt;body&gt;
Click Me&lt;input type=&quot;checkbox&quot;&gt;&lt;br&gt;
     &lt;span&gt;&lt;/span&gt;
     &lt;span&gt;&lt;/span&gt;
     &lt;span&gt;!!!some text!!!&lt;/span&gt;
     &lt;span&gt;&lt;/span&gt;
     &lt;span&gt;&lt;/span&gt;
 repeat it for a few thousand times
&lt;/body&gt;

I don&apos;t see any spinning anymore. So this is about iterating over massive amount of _visually empty_ content (see nextVisuallyDistinctCandidate()).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1878595</commentid>
    <comment_count>11</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2022-06-27 14:41:30 -0700</bug_when>
    <thetext>Sounds like this is unrelated to shadow DOM. It&apos;s a good bug to address nonetheless.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>429874</attachid>
            <date>2021-05-27 06:55:04 -0700</date>
            <delta_ts>2021-05-27 06:55:04 -0700</delta_ts>
            <desc>Code reproduction</desc>
            <filename>index.html</filename>
            <type>text/html</type>
            <size>2846</size>
            <attacher name="Liam DeBeasi">ldebeasi</attacher>
            
              <data encoding="base64">CjwhRE9DVFlQRSBodG1sPgo8aHRtbD4KICA8aGVhZD4KICAgIDx0aXRsZT5TaGFkb3cgVGVzdDwv
dGl0bGU+CiAgICA8bWV0YSBuYW1lPSJ2aWV3cG9ydCIgY29udGVudD0id2lkdGg9ZGV2aWNlLXdp
ZHRoLCBpbml0aWFsLXNjYWxlPTEuMCwgbWluaW11bS1zY2FsZT0xLjAsIG1heGltdW0tc2NhbGU9
MS4wLCB1c2VyLXNjYWxhYmxlPW5vIj4KICA8L2hlYWQ+Cgo8Ym9keT4KICA8YXBwLWNvbnRlbnQg
Y2xhc3M9ImNvbnRlbnQiPjwvYXBwLWNvbnRlbnQ+CgogIDxzY3JpcHQ+CiAgY2xhc3MgQXBwQ29u
dGVudCBleHRlbmRzIEhUTUxFbGVtZW50IHsKICAgIGNvbnN0cnVjdG9yKCkgewogICAgICBzdXBl
cigpOwogICAgICAKICAgICAgdGhpcwogICAgICAgIC5hdHRhY2hTaGFkb3coeyBtb2RlOiAnb3Bl
bicgfSkKICAgICAgICAuaW5uZXJIVE1MID0gYDxzbG90Pjwvc2xvdD5gOyAgIAogICAgfQogIH0K
ICAKICBjbGFzcyBBcHBJdGVtIGV4dGVuZHMgSFRNTEVsZW1lbnQgewogICAgY29uc3RydWN0b3Io
KSB7CiAgICAgIHN1cGVyKCk7CgogICAgICB0aGlzCiAgICAgICAgLmF0dGFjaFNoYWRvdyh7IG1v
ZGU6ICdvcGVuJyB9KQogICAgICAgIC5pbm5lckhUTUwgPSBgCiAgICAgICAgPHN0eWxlPgogICAg
ICAgIDpob3N0IHsKICAgICAgICAgIC0tbXktdmFyLWE6IDBweDsKICAgICAgICAgIC0tbXktdmFy
LWI6IDBweDsKICAgICAgICAgIC0tbXktdmFyLWM6IDBweDsKICAgICAgICAgIC0tbXktdmFyLWQ6
IDBweDsKICAgICAgICAgIC0tbXktdmFyLWU6IDBweDsKICAgICAgICAgIC0tbXktdmFyLWY6IDBw
eDsKICAgICAgICAgIC0tbXktdmFyLWc6IDBweDsKICAgICAgICAgIC0tbXktdmFyLWg6IDBweDsK
ICAgICAgICAgIC0tbXktdmFyLWk6IDBweDsKICAgICAgICAgIC0tbXktdmFyLWo6IDBweDsKICAg
ICAgICAgIC0tbXktdmFyLWs6IDBweDsKICAgICAgICAgIC0tbXktdmFyLWw6IDBweDsKICAgICAg
ICAgIC0tbXktdmFyLW06IDBweDsKICAgICAgICAgIC0tbXktdmFyLW46IDBweDsKICAgICAgICAg
IC0tbXktdmFyLW86IDBweDsKICAgICAgICAgIC0tbXktdmFyLXA6IDBweDsKICAgICAgICAgIC0t
bXktdmFyLXE6IDBweDsKICAgICAgICAgIC0tbXktdmFyLXI6IDBweDsKICAgICAgICAgIC0tbXkt
dmFyLXM6IDBweDsKICAgICAgICAgI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