<?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>236286</bug_id>
          
          <creation_ts>2022-02-07 21:46:57 -0800</creation_ts>
          <short_desc>Reduce allocations and increase thread safety of constructedPath</short_desc>
          <delta_ts>2022-02-08 09:47:06 -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>New Bugs</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</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="Alex Christensen">achristensen</reporter>
          <assigned_to name="Alex Christensen">achristensen</assigned_to>
          <cc>cdumez</cc>
    
    <cc>darin</cc>
    
    <cc>ggaren</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1838529</commentid>
    <comment_count>0</comment_count>
    <who name="Alex Christensen">achristensen</who>
    <bug_when>2022-02-07 21:46:57 -0800</bug_when>
    <thetext>Reduce allocations and increase thread safety of constructedPath</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1838531</commentid>
    <comment_count>1</comment_count>
      <attachid>451208</attachid>
    <who name="Alex Christensen">achristensen</who>
    <bug_when>2022-02-07 21:47:42 -0800</bug_when>
    <thetext>Created attachment 451208
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1838532</commentid>
    <comment_count>2</comment_count>
    <who name="Alex Christensen">achristensen</who>
    <bug_when>2022-02-07 21:47:46 -0800</bug_when>
    <thetext>&lt;rdar://problem/86904276&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1838651</commentid>
    <comment_count>3</comment_count>
      <attachid>451208</attachid>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2022-02-08 07:27:31 -0800</bug_when>
    <thetext>Comment on attachment 451208
Patch

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

r=me with improvement suggestion.

&gt; Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp:85
&gt; +    static auto* prefix(&quot;ContentRuleList-&quot;);

I think you could use:
static const prefix[] = &quot;ContentRuleList-&quot;;

&gt; Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp:524
&gt; +        auto prefixLength = strlen(prefix);

`sizeof(prefix) - 1`

which would be a bit more efficient.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1838702</commentid>
    <comment_count>4</comment_count>
      <attachid>451208</attachid>
    <who name="Alex Christensen">achristensen</who>
    <bug_when>2022-02-08 08:59:38 -0800</bug_when>
    <thetext>Comment on attachment 451208
Patch

The optimizer is able to see that they are the same.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1838703</commentid>
    <comment_count>5</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2022-02-08 09:04:53 -0800</bug_when>
    <thetext>Committed r289380 (246968@main): &lt;https://commits.webkit.org/246968@main&gt;

All reviewed patches have been landed. Closing bug and clearing flags on attachment 451208.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1838715</commentid>
    <comment_count>6</comment_count>
      <attachid>451208</attachid>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2022-02-08 09:21:43 -0800</bug_when>
    <thetext>Comment on attachment 451208
Patch

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

&gt;&gt; Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp:85
&gt;&gt; +    static auto* prefix(&quot;ContentRuleList-&quot;);
&gt; 
&gt; I think you could use:
&gt; static const prefix[] = &quot;ContentRuleList-&quot;;

Whether you want to keep calling strlen() or not fine. But I believe that:
`static const prefix[] = &quot;ContentRuleList-&quot;;`
is strictly superior to:
`static auto* prefix(&quot;ContentRuleList-&quot;);`</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1838718</commentid>
    <comment_count>7</comment_count>
      <attachid>451208</attachid>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2022-02-08 09:39:12 -0800</bug_when>
    <thetext>Comment on attachment 451208
Patch

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

&gt;&gt;&gt; Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp:85
&gt;&gt;&gt; +    static auto* prefix(&quot;ContentRuleList-&quot;);
&gt;&gt; 
&gt;&gt; I think you could use:
&gt;&gt; static const prefix[] = &quot;ContentRuleList-&quot;;
&gt; 
&gt; Whether you want to keep calling strlen() or not fine. But I believe that:
&gt; `static const prefix[] = &quot;ContentRuleList-&quot;;`
&gt; is strictly superior to:
&gt; `static auto* prefix(&quot;ContentRuleList-&quot;);`

In particular, I believe  the using the const array will allow the compiler to put it in the .rodata section of the binary, which may have an impact of perf.

This is unrelated to the fact that strlen() may not may not be optimized in this case.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1838719</commentid>
    <comment_count>8</comment_count>
      <attachid>451208</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2022-02-08 09:39:28 -0800</bug_when>
    <thetext>Comment on attachment 451208
Patch

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

&gt;&gt;&gt; Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp:85
&gt;&gt;&gt; +    static auto* prefix(&quot;ContentRuleList-&quot;);
&gt;&gt; 
&gt;&gt; I think you could use:
&gt;&gt; static const prefix[] = &quot;ContentRuleList-&quot;;
&gt; 
&gt; Whether you want to keep calling strlen() or not fine. But I believe that:
&gt; `static const prefix[] = &quot;ContentRuleList-&quot;;`
&gt; is strictly superior to:
&gt; `static auto* prefix(&quot;ContentRuleList-&quot;);`

I like one of these:

    constexpr auto prefix = &quot;ContentRuleList-&quot;;
    constexpr auto prefix[] = &quot;ContentRuleList-&quot;;

&gt;&gt; Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp:524
&gt;&gt; +        auto prefixLength = strlen(prefix);
&gt; 
&gt; `sizeof(prefix) - 1`
&gt; 
&gt; which would be a bit more efficient.

In clang strlen is optimized and constant folded, so there is no performance difference.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1838720</commentid>
    <comment_count>9</comment_count>
    <who name="Darin Adler">darin</who>
    <bug_when>2022-02-08 09:42:33 -0800</bug_when>
    <thetext>I did a little testing and the code is identical between these two:

    constexpr auto prefix = &quot;ContentRuleList-&quot;;
    constexpr char prefix[] = &quot;ContentRuleList-&quot;;

Both put the string into the .rodata section.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1838722</commentid>
    <comment_count>10</comment_count>
      <attachid>451208</attachid>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2022-02-08 09:43:58 -0800</bug_when>
    <thetext>Comment on attachment 451208
Patch

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

&gt;&gt;&gt;&gt;&gt; Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp:85
&gt;&gt;&gt;&gt;&gt; +    static auto* prefix(&quot;ContentRuleList-&quot;);
&gt;&gt;&gt;&gt; 
&gt;&gt;&gt;&gt; I think you could use:
&gt;&gt;&gt;&gt; static const prefix[] = &quot;ContentRuleList-&quot;;
&gt;&gt;&gt; 
&gt;&gt;&gt; Whether you want to keep calling strlen() or not fine. But I believe that:
&gt;&gt;&gt; `static const prefix[] = &quot;ContentRuleList-&quot;;`
&gt;&gt;&gt; is strictly superior to:
&gt;&gt;&gt; `static auto* prefix(&quot;ContentRuleList-&quot;);`
&gt;&gt; 
&gt;&gt; In particular, I believe  the using the const array will allow the compiler to put it in the .rodata section of the binary, which may have an impact of perf.
&gt;&gt; 
&gt;&gt; This is unrelated to the fact that strlen() may not may not be optimized in this case.
&gt; 
&gt; I like one of these:
&gt; 
&gt;     constexpr auto prefix = &quot;ContentRuleList-&quot;;
&gt;     constexpr auto prefix[] = &quot;ContentRuleList-&quot;;

Right but the code that landed used `static auto* prefix(&quot;ContentRuleList-&quot;);` and I am less convinced this goes into .rodata (though I haven&apos;t verified).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1838728</commentid>
    <comment_count>11</comment_count>
      <attachid>451208</attachid>
    <who name="Darin Adler">darin</who>
    <bug_when>2022-02-08 09:47:06 -0800</bug_when>
    <thetext>Comment on attachment 451208
Patch

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

&gt;&gt;&gt;&gt;&gt;&gt; Source/WebKit/UIProcess/API/APIContentRuleListStore.cpp:85
&gt;&gt;&gt;&gt;&gt;&gt; +    static auto* prefix(&quot;ContentRuleList-&quot;);
&gt;&gt;&gt;&gt;&gt; 
&gt;&gt;&gt;&gt;&gt; I think you could use:
&gt;&gt;&gt;&gt;&gt; static const prefix[] = &quot;ContentRuleList-&quot;;
&gt;&gt;&gt;&gt; 
&gt;&gt;&gt;&gt; Whether you want to keep calling strlen() or not fine. But I believe that:
&gt;&gt;&gt;&gt; `static const prefix[] = &quot;ContentRuleList-&quot;;`
&gt;&gt;&gt;&gt; is strictly superior to:
&gt;&gt;&gt;&gt; `static auto* prefix(&quot;ContentRuleList-&quot;);`
&gt;&gt;&gt; 
&gt;&gt;&gt; In particular, I believe  the using the const array will allow the compiler to put it in the .rodata section of the binary, which may have an impact of perf.
&gt;&gt;&gt; 
&gt;&gt;&gt; This is unrelated to the fact that strlen() may not may not be optimized in this case.
&gt;&gt; 
&gt;&gt; I like one of these:
&gt;&gt; 
&gt;&gt;     constexpr auto prefix = &quot;ContentRuleList-&quot;;
&gt;&gt;     constexpr auto prefix[] = &quot;ContentRuleList-&quot;;
&gt; 
&gt; Right but the code that landed used `static auto* prefix(&quot;ContentRuleList-&quot;);` and I am less convinced this goes into .rodata (though I haven&apos;t verified).

Yes, I think it has too little const. It’s a non-const global variable. More constexpr would fix it. Whether you left &quot;static&quot; in or not, and whether you used &quot;auto*&quot; or &quot;auto&quot;.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>451208</attachid>
            <date>2022-02-07 21:47:42 -0800</date>
            <delta_ts>2022-02-08 09:04:55 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>bug-236286-20220207214741.patch</filename>
            <type>text/plain</type>
            <size>2601</size>
            <attacher name="Alex Christensen">achristensen</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjg5MjM3CmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViS2l0L0No
YW5nZUxvZyBiL1NvdXJjZS9XZWJLaXQvQ2hhbmdlTG9nCmluZGV4IDllMTZmOTBhMGZhZDY5MmUx
MDA5ZTkyZDNlNDQzNDg4ZTJiZGJlMDkuLmY1NjZlZDUxNWQ2NTRiY2MxNDM5ZWQ5MTk0MmE2ZmRh
ODY0NDNiZGIgMTAwNjQ0Ci0tLSBhL1NvdXJjZS9XZWJLaXQvQ2hhbmdlTG9nCisrKyBiL1NvdXJj
ZS9XZWJLaXQvQ2hhbmdlTG9nCkBAIC0xLDMgKzEsMTUgQEAKKzIwMjItMDItMDcgIEFsZXggQ2hy
aXN0ZW5zZW4gIDxhY2hyaXN0ZW5zZW5Ad2Via2l0Lm9yZz4KKworICAgICAgICBSZWR1Y2UgYWxs
b2NhdGlvbnMgYW5kIGluY3JlYXNlIHRocmVhZCBzYWZldHkgb2YgY29uc3RydWN0ZWRQYXRoCisg
ICAgICAgIGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0yMzYyODYKKyAg
ICAgICAgPHJ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7ICp0
aGlzIH0sIHN0b3JlUGF0aCA9IG1fc3RvcmVQYXRoLmlzb2xhdGVkQ29weSgpLCBjb21wbGV0aW9u
SGFuZGxlciA9IFdURk1vdmUoY29tcGxldGlvbkhhbmRsZXIpXSgpIG11dGFibGUgewogICAgICAg
ICBhdXRvIHByZWZpeCA9IGNvbnN0cnVjdGVkUGF0aFByZWZpeChmYWxzZSAvKmxlZ2FjeSovKTsK
LSAgICAgICAgYXV0byBwcmVmaXhMZW5ndGggPSBwcmVmaXgubGVuZ3RoKCk7CisgICAgICAgIGF1
dG8gcHJlZml4TGVuZ3RoID0gc3RybGVuKHByZWZpeCk7CiAgICAgICAgIGF1dG8gbGVnYWN5UHJl
Zml4ID0gY29uc3RydWN0ZWRQYXRoUHJlZml4KHRydWUgLypsZWdhY3kqLyk7Ci0gICAgICAgIGF1
dG8gbGVnYWN5UHJlZml4TGVuZ3RoID0gbGVnYWN5UHJlZml4Lmxlbmd0aCgpOworICAgICAgICBh
dXRvIGxlZ2FjeVByZWZpeExlbmd0aCA9IHN0cmxlbihsZWdhY3lQcmVmaXgpOwogCiAgICAgICAg
IFZlY3RvcjxXVEY6OlN0cmluZz4gaWRlbnRpZmllcnM7CiAgICAgICAgIGZvciAoYXV0byYgZmls
ZU5hbWUgOiBsaXN0RGlyZWN0b3J5KHN0b3JlUGF0aCkpIHsK
</data>

          </attachment>
      

    </bug>

</bugzilla>