<?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>20209</bug_id>
          
          <creation_ts>2008-07-29 06:52:25 -0700</creation_ts>
          <short_desc>Atomize constant strings</short_desc>
          <delta_ts>2008-07-30 08:35:33 -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>JavaScriptCore</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>OS X 10.5</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Gavin Barraclough">barraclough</reporter>
          <assigned_to name="Gavin Barraclough">barraclough</assigned_to>
          <cc>ap</cc>
    
    <cc>ggaren</cc>
    
    <cc>oliver</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>87265</commentid>
    <comment_count>0</comment_count>
    <who name="Gavin Barraclough">barraclough</who>
    <bug_when>2008-07-29 06:52:25 -0700</bug_when>
    <thetext>Example of code that currently performs poorly:

function get(self, keyword) {
    // do stuff
    return self[keyword];
}

function f1() {
    var localGet = get;
    var object = {};
    var start = new Date;
    for (var i =0; i &lt; 10000000; i++)
        get(object, &apos;foo&apos;);
    print(&quot;f1 time taken: &quot; + (new Date - start)/1000 + &quot;s&quot;);
}

function f2() {
    var object = {};
    var startTime = new Date;
    for (var i =0; i &lt; 10000000; i++)
        object[&apos;foo&apos;];
    print(&quot;f2 time taken: &quot; + (new Date - startTime)/1000 + &quot;s&quot;);
}

f1();
f2();

The problem in the above script is that the string &apos;foo&apos; is used twice as an identifier.  Only &apos;foo&apos; from f1() will be added to the identifier map, degrading the performance of f2().  Fix this by turning constant strings into identifiers during code generation.

(patch following).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>87266</commentid>
    <comment_count>1</comment_count>
      <attachid>22537</attachid>
    <who name="Gavin Barraclough">barraclough</who>
    <bug_when>2008-07-29 06:53:21 -0700</bug_when>
    <thetext>Created attachment 22537
fix</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>87269</commentid>
    <comment_count>2</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2008-07-29 08:24:11 -0700</bug_when>
    <thetext>I&apos;m getting some weird results on the above test with a r35249 nightly. f1 takes ~2.3s, while f2 alternates between 1.6s and 0.9s (odd runs are slow, even runs are fast, no values in between).

On a Shark profile of a slow run, 36% of time is spent in Identifier::addSlowCase, and for fast runs, this function is not on the profile.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>87335</commentid>
    <comment_count>3</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2008-07-29 15:44:42 -0700</bug_when>
    <thetext>&gt; I&apos;m getting some weird results on the above test with a r35249 nightly. f1
&gt; takes ~2.3s, while f2 alternates between 1.6s and 0.9s (odd runs are slow, even
&gt; runs are fast, no values in between).

Perhaps the garbage collector&apos;s effect on the lifetime of an identifier is in play here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>87336</commentid>
    <comment_count>4</comment_count>
      <attachid>22537</attachid>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2008-07-29 15:52:22 -0700</bug_when>
    <thetext>Comment on attachment 22537
fix

Note that the patch I suggested to convert a[&apos;s&apos;] to a.s during codegen would also fix this particular test case.

+    // String literals are atomized (internalized) in the identifier map.

Probably better to state the why here, rather than the what. For example, &quot;We atomize constant strings, in case they&apos;re later used in property lookup.&quot;

+        a script contains multiple identical strings that are used as keys keys to identify

Typo: &quot;keys keys&quot; should be &quot;keys.&quot;

Please add a bugzilla link to the ChangeLog.

r=me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>87384</commentid>
    <comment_count>5</comment_count>
    <who name="Gavin Barraclough">barraclough</who>
    <bug_when>2008-07-30 07:56:55 -0700</bug_when>
    <thetext>(In reply to comment #4)
&gt; (From update of attachment 22537 [edit])
&gt; Note that the patch I suggested to convert a[&apos;s&apos;] to a.s during codegen would
&gt; also fix this particular test case.

Ah yes, that&apos;s quite true, thanks – I had writing a test case for this on my todo list, since we don&apos;t hit it in sunspider – that&apos;s one problem solved! – will raise a bug &amp; submit a patch.
G.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>87385</commentid>
    <comment_count>6</comment_count>
    <who name="Gavin Barraclough">barraclough</who>
    <bug_when>2008-07-30 07:59:24 -0700</bug_when>
    <thetext>Sending        JavaScriptCore/ChangeLog
Sending        JavaScriptCore/kjs/nodes.cpp
Transmitting file data ..
Committed revision 35446.

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>87388</commentid>
    <comment_count>7</comment_count>
    <who name="Gavin Barraclough">barraclough</who>
    <bug_when>2008-07-30 08:35:33 -0700</bug_when>
    <thetext>Optimize [ &quot;constant string&quot; ] into an identifier access.

https://bugs.webkit.org/show_bug.cgi?id=20227


</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>22537</attachid>
            <date>2008-07-29 06:53:21 -0700</date>
            <delta_ts>2008-07-29 15:52:22 -0700</delta_ts>
            <desc>fix</desc>
            <filename>patch_const_str.txt</filename>
            <type>text/plain</type>
            <size>1480</size>
            <attacher name="Gavin Barraclough">barraclough</attacher>
            
              <data encoding="base64">SW5kZXg6IEphdmFTY3JpcHRDb3JlL2tqcy9ub2Rlcy5jcHAKPT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT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yaXB0Q29yZS9DaGFuZ2VMb2cJKHJldmlzaW9uIDM1
NDE4KQorKysgSmF2YVNjcmlwdENvcmUvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBAIC0xLDMg
KzEsMTUgQEAKKzIwMDgtMDctMjkgIEdhdmluIEJhcnJhY2xvdWdoICA8YmFycmFjbG91Z2hAYXBw
bGUuY29tPgorCisgICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisgICAgICAg
IEF0b21pemUgY29uc3RhbnQgc3RyaW5ncy4gIFByZXZlbnRzIHNpZ25pZmljYW50IHBlcmZvcm1h
bmNlIGRlZ3JhZGF0aW9uIHNlZW4gd2hlbgorICAgICAgICBhIHNjcmlwdCBjb250YWlucyBtdWx0
aXBsZSBpZGVudGljYWwgc3RyaW5ncyB0aGF0IGFyZSB1c2VkIGFzIGtleXMga2V5cyB0byBpZGVu
dGlmeQorICAgICAgICBwcm9wZXJ0aWVzIG9uIG9iamVjdHMuCisKKyAgICAgICAgTm8gcGVyZm9y
bWFuY2UgY2hhbmdlIG9uIFN1blNwaWRlci4KKworICAgICAgICAqIGtqcy9ub2Rlcy5jcHA6IEF0
b21pemUgY29uc3RhbnQgc3RyaW5ncy4KKwogMjAwOC0wNy0yOSAgQWxleGV5IFByb3NrdXJ5YWtv
diAgPGFwQHdlYmtpdC5vcmc+CiAKICAgICAgICAgUmV2aWV3ZWQgYnkgT2xpdmVyIEh1bnQuCg==
</data>
<flag name="review"
          id="9944"
          type_id="1"
          status="+"
          setter="ggaren"
    />
          </attachment>
      

    </bug>

</bugzilla>