<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[169815] trunk/Source/JavaScriptCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/169815">169815</a></dd>
<dt>Author</dt> <dd>akling@apple.com</dd>
<dt>Date</dt> <dd>2014-06-11 11:40:13 -0700 (Wed, 11 Jun 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Some JSValue::get() micro-optimzations.
&lt;https://webkit.org/b/133739&gt;

Tighten some of the property lookup code to improve performance of the
eagerly reified prototype attributes:

- Instead of converting the property name to an integer at every step
  in the prototype chain, move that to a separate pass at the end
  since it should be a rare case.

- Cache the StructureIDTable in a local instead of fetching it from
  the Heap on every step.

- Make fillCustomGetterPropertySlot inline. It was out-of-lined based
  on the assumption that clients would mostly be cacheable GetByIds,
  and it gets pretty hot (~1%) in GetByVal.

- Pass the Structure directly to fillCustomGetterPropertySlot instead
  of refetching it from the StructureIDTable.

Reviewed by Geoff Garen.

* runtime/JSObject.cpp:
(JSC::JSObject::fillCustomGetterPropertySlot): Deleted.
* runtime/JSObject.h:
(JSC::JSObject::inlineGetOwnPropertySlot):
(JSC::JSObject::fillCustomGetterPropertySlot):
(JSC::JSObject::getOwnPropertySlot):
(JSC::JSObject::fastGetOwnPropertySlot):
(JSC::JSObject::getPropertySlot):
(JSC::JSObject::getOwnPropertySlotSlow): Deleted.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSObjectcpp">trunk/Source/JavaScriptCore/runtime/JSObject.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSObjecth">trunk/Source/JavaScriptCore/runtime/JSObject.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (169814 => 169815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2014-06-11 18:36:07 UTC (rev 169814)
+++ trunk/Source/JavaScriptCore/ChangeLog        2014-06-11 18:40:13 UTC (rev 169815)
</span><span class="lines">@@ -1,3 +1,37 @@
</span><ins>+2014-06-11  Andreas Kling  &lt;akling@apple.com&gt;
+
+        Some JSValue::get() micro-optimzations.
+        &lt;https://webkit.org/b/133739&gt;
+
+        Tighten some of the property lookup code to improve performance of the
+        eagerly reified prototype attributes:
+
+        - Instead of converting the property name to an integer at every step
+          in the prototype chain, move that to a separate pass at the end
+          since it should be a rare case.
+
+        - Cache the StructureIDTable in a local instead of fetching it from
+          the Heap on every step.
+
+        - Make fillCustomGetterPropertySlot inline. It was out-of-lined based
+          on the assumption that clients would mostly be cacheable GetByIds,
+          and it gets pretty hot (~1%) in GetByVal.
+
+        - Pass the Structure directly to fillCustomGetterPropertySlot instead
+          of refetching it from the StructureIDTable.
+
+        Reviewed by Geoff Garen.
+
+        * runtime/JSObject.cpp:
+        (JSC::JSObject::fillCustomGetterPropertySlot): Deleted.
+        * runtime/JSObject.h:
+        (JSC::JSObject::inlineGetOwnPropertySlot):
+        (JSC::JSObject::fillCustomGetterPropertySlot):
+        (JSC::JSObject::getOwnPropertySlot):
+        (JSC::JSObject::fastGetOwnPropertySlot):
+        (JSC::JSObject::getPropertySlot):
+        (JSC::JSObject::getOwnPropertySlotSlow): Deleted.
+
</ins><span class="cx"> 2014-06-10  Sam Weinig  &lt;sam@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Don't create a HashTable for JSObjects that use eager reification
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSObject.cpp (169814 => 169815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSObject.cpp        2014-06-11 18:36:07 UTC (rev 169814)
+++ trunk/Source/JavaScriptCore/runtime/JSObject.cpp        2014-06-11 18:40:13 UTC (rev 169815)
</span><span class="lines">@@ -1690,15 +1690,6 @@
</span><span class="cx">     slot.setCacheableGetterSlot(this, attributes, jsCast&lt;GetterSetter*&gt;(getterSetter), offset);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-NEVER_INLINE void JSObject::fillCustomGetterPropertySlot(PropertySlot&amp; slot, JSValue customGetterSetter, unsigned attributes)
-{
-    if (structure()-&gt;isDictionary()) {
-        slot.setCustom(this, attributes, jsCast&lt;CustomGetterSetter*&gt;(customGetterSetter)-&gt;getter());
-        return;
-    }
-    slot.setCacheableCustom(this, attributes, jsCast&lt;CustomGetterSetter*&gt;(customGetterSetter)-&gt;getter());
-}
-
</del><span class="cx"> void JSObject::putIndexedDescriptor(ExecState* exec, SparseArrayEntry* entryInMap, const PropertyDescriptor&amp; descriptor, PropertyDescriptor&amp; oldDescriptor)
</span><span class="cx"> {
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSObjecth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSObject.h (169814 => 169815)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSObject.h        2014-06-11 18:36:07 UTC (rev 169814)
+++ trunk/Source/JavaScriptCore/runtime/JSObject.h        2014-06-11 18:40:13 UTC (rev 169815)
</span><span class="lines">@@ -31,6 +31,7 @@
</span><span class="cx"> #include &quot;ClassInfo.h&quot;
</span><span class="cx"> #include &quot;CommonIdentifiers.h&quot;
</span><span class="cx"> #include &quot;CopyWriteBarrier.h&quot;
</span><ins>+#include &quot;CustomGetterSetter.h&quot;
</ins><span class="cx"> #include &quot;DeferGC.h&quot;
</span><span class="cx"> #include &quot;Heap.h&quot;
</span><span class="cx"> #include &quot;HeapInlines.h&quot;
</span><span class="lines">@@ -957,9 +958,9 @@
</span><span class="cx">     template&lt;PutMode&gt;
</span><span class="cx">     bool putDirectInternal(VM&amp;, PropertyName, JSValue, unsigned attr, PutPropertySlot&amp;, JSCell*);
</span><span class="cx"> 
</span><del>-    bool inlineGetOwnPropertySlot(ExecState*, VM&amp;, Structure&amp;, PropertyName, PropertySlot&amp;);
</del><ins>+    bool inlineGetOwnPropertySlot(VM&amp;, Structure&amp;, PropertyName, PropertySlot&amp;);
</ins><span class="cx">     JS_EXPORT_PRIVATE void fillGetterPropertySlot(PropertySlot&amp;, JSValue, unsigned, PropertyOffset);
</span><del>-    JS_EXPORT_PRIVATE void fillCustomGetterPropertySlot(PropertySlot&amp;, JSValue, unsigned);
</del><ins>+    void fillCustomGetterPropertySlot(PropertySlot&amp;, JSValue, unsigned, Structure&amp;);
</ins><span class="cx"> 
</span><span class="cx">     const HashTableValue* findPropertyHashEntry(VM&amp;, PropertyName) const;
</span><span class="cx">         
</span><span class="lines">@@ -972,8 +973,6 @@
</span><span class="cx">     unsigned getNewVectorLength(unsigned currentVectorLength, unsigned currentLength, unsigned desiredLength);
</span><span class="cx">     unsigned getNewVectorLength(unsigned desiredLength);
</span><span class="cx"> 
</span><del>-    bool getOwnPropertySlotSlow(ExecState*, PropertyName, PropertySlot&amp;);
-        
</del><span class="cx">     ArrayStorage* constructConvertedArrayStorageWithoutCopyingElements(VM&amp;, unsigned neededLength);
</span><span class="cx">         
</span><span class="cx">     JS_EXPORT_PRIVATE void setIndexQuicklyToUndecided(VM&amp;, unsigned index, JSValue);
</span><span class="lines">@@ -1212,31 +1211,32 @@
</span><span class="cx">     return structure()-&gt;storedPrototype();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-ALWAYS_INLINE bool JSObject::inlineGetOwnPropertySlot(ExecState* exec, VM&amp; vm, Structure&amp; structure, PropertyName propertyName, PropertySlot&amp; slot)
</del><ins>+ALWAYS_INLINE bool JSObject::inlineGetOwnPropertySlot(VM&amp; vm, Structure&amp; structure, PropertyName propertyName, PropertySlot&amp; slot)
</ins><span class="cx"> {
</span><span class="cx">     unsigned attributes;
</span><span class="cx">     JSCell* specific;
</span><span class="cx">     PropertyOffset offset = structure.get(vm, propertyName, attributes, specific);
</span><del>-    if (LIKELY(isValidOffset(offset))) {
-        JSValue value = getDirect(offset);
-        if (structure.hasGetterSetterProperties() &amp;&amp; value.isGetterSetter())
-            fillGetterPropertySlot(slot, value, attributes, offset);
-        else if (structure.hasCustomGetterSetterProperties() &amp;&amp; value.isCustomGetterSetter())
-            fillCustomGetterPropertySlot(slot, value, attributes);
-        else
-            slot.setValue(this, attributes, value, offset);
-        return true;
-    }
</del><ins>+    if (!isValidOffset(offset))
+        return false;
</ins><span class="cx"> 
</span><del>-    return getOwnPropertySlotSlow(exec, propertyName, slot);
</del><ins>+    JSValue value = getDirect(offset);
+    if (structure.hasGetterSetterProperties() &amp;&amp; value.isGetterSetter())
+        fillGetterPropertySlot(slot, value, attributes, offset);
+    else if (structure.hasCustomGetterSetterProperties() &amp;&amp; value.isCustomGetterSetter())
+        fillCustomGetterPropertySlot(slot, value, attributes, structure);
+    else
+        slot.setValue(this, attributes, value, offset);
+
+    return true;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-inline bool JSObject::getOwnPropertySlotSlow(ExecState* exec, PropertyName propertyName, PropertySlot&amp; slot)
</del><ins>+ALWAYS_INLINE void JSObject::fillCustomGetterPropertySlot(PropertySlot&amp; slot, JSValue customGetterSetter, unsigned attributes, Structure&amp; structure)
</ins><span class="cx"> {
</span><del>-    unsigned i = propertyName.asIndex();
-    if (i != PropertyName::NotAnIndex)
-        return getOwnPropertySlotByIndex(this, exec, i, slot);
-    return false;
</del><ins>+    if (structure.isDictionary()) {
+        slot.setCustom(this, attributes, jsCast&lt;CustomGetterSetter*&gt;(customGetterSetter)-&gt;getter());
+        return;
+    }
+    slot.setCacheableCustom(this, attributes, jsCast&lt;CustomGetterSetter*&gt;(customGetterSetter)-&gt;getter());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> // It may seem crazy to inline a function this large, especially a virtual function,
</span><span class="lines">@@ -1246,13 +1246,18 @@
</span><span class="cx"> {
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span><span class="cx">     Structure&amp; structure = *object-&gt;structure(vm);
</span><del>-    return object-&gt;inlineGetOwnPropertySlot(exec, vm, structure, propertyName, slot);
</del><ins>+    if (object-&gt;inlineGetOwnPropertySlot(vm, structure, propertyName, slot))
+        return true;
+    unsigned index = propertyName.asIndex();
+    if (index != PropertyName::NotAnIndex)
+        return getOwnPropertySlotByIndex(object, exec, index, slot);
+    return false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ALWAYS_INLINE bool JSObject::fastGetOwnPropertySlot(ExecState* exec, VM&amp; vm, Structure&amp; structure, PropertyName propertyName, PropertySlot&amp; slot)
</span><span class="cx"> {
</span><span class="cx">     if (!TypeInfo::overridesGetOwnPropertySlot(inlineTypeFlags()))
</span><del>-        return asObject(this)-&gt;inlineGetOwnPropertySlot(exec, vm, structure, propertyName, slot);
</del><ins>+        return asObject(this)-&gt;inlineGetOwnPropertySlot(vm, structure, propertyName, slot);
</ins><span class="cx">     return structure.classInfo()-&gt;methodTable.getOwnPropertySlot(this, exec, propertyName, slot);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -1261,24 +1266,31 @@
</span><span class="cx"> ALWAYS_INLINE bool JSObject::getPropertySlot(ExecState* exec, PropertyName propertyName, PropertySlot&amp; slot)
</span><span class="cx"> {
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span><ins>+    auto&amp; structureIDTable = vm.heap.structureIDTable();
</ins><span class="cx">     JSObject* object = this;
</span><span class="cx">     while (true) {
</span><del>-        Structure&amp; structure = *object-&gt;structure(vm);
</del><ins>+        Structure&amp; structure = *structureIDTable.get(object-&gt;structureID());
</ins><span class="cx">         if (object-&gt;fastGetOwnPropertySlot(exec, vm, structure, propertyName, slot))
</span><span class="cx">             return true;
</span><span class="cx">         JSValue prototype = structure.storedPrototype();
</span><span class="cx">         if (!prototype.isObject())
</span><del>-            return false;
</del><ins>+            break;
</ins><span class="cx">         object = asObject(prototype);
</span><span class="cx">     }
</span><ins>+
+    unsigned index = propertyName.asIndex();
+    if (index != PropertyName::NotAnIndex)
+        return getPropertySlot(exec, index, slot);
+    return false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> ALWAYS_INLINE bool JSObject::getPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot&amp; slot)
</span><span class="cx"> {
</span><span class="cx">     VM&amp; vm = exec-&gt;vm();
</span><ins>+    auto&amp; structureIDTable = vm.heap.structureIDTable();
</ins><span class="cx">     JSObject* object = this;
</span><span class="cx">     while (true) {
</span><del>-        Structure&amp; structure = *object-&gt;structure(vm);
</del><ins>+        Structure&amp; structure = *structureIDTable.get(object-&gt;structureID());
</ins><span class="cx">         if (structure.classInfo()-&gt;methodTable.getOwnPropertySlotByIndex(object, exec, propertyName, slot))
</span><span class="cx">             return true;
</span><span class="cx">         JSValue prototype = structure.storedPrototype();
</span></span></pre>
</div>
</div>

</body>
</html>