<?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>106667</bug_id>
          
          <creation_ts>2013-01-11 08:29:23 -0800</creation_ts>
          <short_desc>[V8] Slightly optimize getWrapperFast()</short_desc>
          <delta_ts>2013-01-17 09:58:20 -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>WebCore JavaScript</component>
          <version>528+ (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></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Kentaro Hara">haraken</reporter>
          <assigned_to name="Kentaro Hara">haraken</assigned_to>
          <cc>abarth</cc>
    
    <cc>dcarney</cc>
    
    <cc>japhet</cc>
    
    <cc>webkit.review.bot</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>805279</commentid>
    <comment_count>0</comment_count>
    <who name="Kentaro Hara">haraken</who>
    <bug_when>2013-01-11 08:29:23 -0800</bug_when>
    <thetext>Slightly optimize getWrapperFast().</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>805283</commentid>
    <comment_count>1</comment_count>
      <attachid>182348</attachid>
    <who name="Kentaro Hara">haraken</who>
    <bug_when>2013-01-11 08:41:35 -0800</bug_when>
    <thetext>Created attachment 182348
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>805373</commentid>
    <comment_count>2</comment_count>
      <attachid>182348</attachid>
    <who name="Adam Barth">abarth</who>
    <bug_when>2013-01-11 10:26:39 -0800</bug_when>
    <thetext>Comment on attachment 182348
Patch

ok</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>805384</commentid>
    <comment_count>3</comment_count>
    <who name="Kentaro Hara">haraken</who>
    <bug_when>2013-01-11 10:34:45 -0800</bug_when>
    <thetext>BTW, what do you think about the following idea?

- Use a class id to indicate whether we&apos;re in the main world or not. Specifically, we can use v8DOMNodeInMainWorldClassId, v8DOMObjectInMainWorldClassId, v8DOMNodeInIsolateWorldClassId, v8DOMObjectInIsolateWorldClassId. Then we can know whether we&apos;re in the main world or not by looking at a class id of info.Holder(). This will simplify a bunch of methods in DOMDataStore.h.

I don&apos;t think this will improve performance because the number of if branches doesn&apos;t change, but it will simplify the confusing if conditions in DOMDataStore.h.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>805391</commentid>
    <comment_count>4</comment_count>
      <attachid>182348</attachid>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2013-01-11 10:38:48 -0800</bug_when>
    <thetext>Comment on attachment 182348
Patch

Clearing flags on attachment: 182348

Committed r139458: &lt;http://trac.webkit.org/changeset/139458&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>805392</commentid>
    <comment_count>5</comment_count>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2013-01-11 10:38:52 -0800</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>805412</commentid>
    <comment_count>6</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2013-01-11 10:52:37 -0800</bug_when>
    <thetext>&gt; BTW, what do you think about the following idea?

I&apos;d rather not pack more bits into the class ID unless there&apos;s a performance gain.  The class ID is a very limited space, and we want to save it for things we really need.

Another idea is to use different ObjectTemplates for the main world and for isolated worlds.  That way we could have two implementations of nextSiblingCallback, one for the main world and one for isolated worlds.  The one for the main world could then skip the &quot;am I in the main world&quot; branch entirely and grab at the inline wrapper directly.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>805423</commentid>
    <comment_count>7</comment_count>
    <who name="Kentaro Hara">haraken</who>
    <bug_when>2013-01-11 11:02:16 -0800</bug_when>
    <thetext>(In reply to comment #6)
&gt; &gt; BTW, what do you think about the following idea?
&gt; 
&gt; I&apos;d rather not pack more bits into the class ID unless there&apos;s a performance gain.  The class ID is a very limited space, and we want to save it for things we really need.

This isn&apos;t quite right. A class ID has 16 bit (although I am trying to reduce the size to 8 bit just right now).


&gt; Another idea is to use different ObjectTemplates for the main world and for isolated worlds.  That way we could have two implementations of nextSiblingCallback, one for the main world and one for isolated worlds.  The one for the main world could then skip the &quot;am I in the main world&quot; branch entirely and grab at the inline wrapper directly.

Sounds like a better approach. (This is the approach Dan is also proposing.) My only concern is that it will complicate the generated code. Specifically, we will need to generate something like the following code for all getters/setters/methods, affecting custom bindings:


template&lt;WorldType world&gt;
struct firstChildAttrGetterStruct {

static v8::Handle&lt;v8::Value&gt; firstChildAttrGetter(v8::Local&lt;v8::String&gt; name, const v8::AccessorInfo&amp; info)
{
    Node* imp = V8Node::toNative(info.Holder());
    return toV8Fast&lt;world&gt;(imp-&gt;firstChild(), info, imp);
}

};

template&lt;&gt;
struct firstChildAttrGetterStruct&lt;MainWorld&gt;;

template&lt;&gt;
struct firstChildAttrGetterStruct&lt;IsolateWorld&gt;;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>805472</commentid>
    <comment_count>8</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2013-01-11 11:42:55 -0800</bug_when>
    <thetext>We can also just generate two copies of the function and skip the templates.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>809305</commentid>
    <comment_count>9</comment_count>
    <who name="Kentaro Hara">haraken</who>
    <bug_when>2013-01-17 06:32:27 -0800</bug_when>
    <thetext>(In reply to comment #8)
&gt; We can also just generate two copies of the function and skip the templates.

For experiment, I removed the following lines to observe the performance impact of generating getters/setters for the main world:

    static v8::Handle&lt;v8::Object&gt; getWrapperFast(T* object, const HolderContainer&amp; container, Wrappable* holder)
    {
        /* if ((!DOMWrapperWorld::isolatedWorldsExist() &amp;&amp; isMainWorldObject(object)) || holderContainsWrapper(container, holder)) { */
            if (mainWorldWrapperIsStoredInObject(object))
                return getWrapperFromObject(object);
            return mainWorldStore()-&gt;m_wrapperMap.get(object);
        /* }
        return current(container.GetIsolate())-&gt;get(object); */
    }

As a result, a micro benchmark for .firstChild improved from 14.1 ns to 13.7 ns. On the other hand, I couldn&apos;t observe any performance difference in Dromaeo/dom-traverse.

So it might not be worth doing the optimization.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>809413</commentid>
    <comment_count>10</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2013-01-17 09:58:20 -0800</bug_when>
    <thetext>Interesting.  Thanks!</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>182348</attachid>
            <date>2013-01-11 08:41:35 -0800</date>
            <delta_ts>2013-01-11 10:38:48 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>bug-106667-20130111173837.patch</filename>
            <type>text/plain</type>
            <size>2719</size>
            <attacher name="Kentaro Hara">haraken</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMTM5MTgzCmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViQ29yZS9D
aGFuZ2VMb2cgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKaW5kZXggNTc3MWY2YTNkZDZjNTY2
ZjBkZDMxZTI1OWRmNmI4YmYyMWNjNjA4My4uNzRjNjIxZTIwZjcxMGEyYmI5MmI4ZDE5ZTczNDcy
OWY1ZWFlNDNjMyAxMDA2NDQKLS0tIGEvU291cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCisrKyBiL1Nv
dXJjZS9XZWJDb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mdldChvYmpl
Y3QpOwogICAgIH0KIAogICAgIHRlbXBsYXRlPHR5cGVuYW1lIFQ+Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>