<?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>75569</bug_id>
          
          <creation_ts>2012-01-04 13:38:43 -0800</creation_ts>
          <short_desc>DOM Attribute tests on Dromaeo spends 2.7% of time in hasSelectorForAttribute</short_desc>
          <delta_ts>2012-01-05 17:08:15 -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>DOM</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="Ryosuke Niwa">rniwa</reporter>
          <assigned_to name="Ryosuke Niwa">rniwa</assigned_to>
          <cc>adamk</cc>
    
    <cc>darin</cc>
    
    <cc>kling</cc>
    
    <cc>koivisto</cc>
    
    <cc>oliver</cc>
    
    <cc>webkit.review.bot</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>529713</commentid>
    <comment_count>0</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-04 13:38:43 -0800</bug_when>
    <thetext>Go to http://dromaeo.com/?dom and profiled WebKit r103959 while it was running DOM Attributes tests.

Besides AtomicString::addSlowCase which accounts for about 12% of time, we spend 2.7% of time in hasSelectorForAttribute. We can probably use bloom filter there as anttik suggested.

	6.6%	6.6%	JavaScriptCore	JSC::IdentifierTable::add(WTF::StringImpl*)
	5.8%	5.8%	JavaScriptCore	WTF::AtomicString::addSlowCase(WTF::StringImpl*)
	5.1%	5.1%	WebCore	WTF::HashTableIterator&lt;WTF::StringImpl*, std::pair&lt;WTF::StringImpl*, JSC::Weak&lt;JSC::JSString&gt; &gt;, WTF::PairFirstExtractor&lt;std::pair&lt;WTF::StringImpl*, JSC::Weak&lt;JSC::JSString&gt; &gt; &gt;, WTF::StringHash, WTF::PairHashTraits&lt;WTF::HashTraits&lt;WTF::StringImpl*&gt;, WTF::HashTraits&lt;JSC::Weak&lt;JSC::JSString&gt; &gt; &gt;, WTF::HashTraits&lt;WTF::StringImpl*&gt; &gt; WTF::HashTable&lt;WTF::StringImpl*, std::pair&lt;WTF::StringImpl*, JSC::Weak&lt;JSC::JSString&gt; &gt;, WTF::PairFirstExtractor&lt;std::pair&lt;WTF::StringImpl*, JSC::Weak&lt;JSC::JSString&gt; &gt; &gt;, WTF::StringHash, WTF::PairHashTraits&lt;WTF::HashTraits&lt;WTF::StringImpl*&gt;, WTF::HashTraits&lt;JSC::Weak&lt;JSC::JSString&gt; &gt; &gt;, WTF::HashTraits&lt;WTF::StringImpl*&gt; &gt;::find&lt;WTF::IdentityHashTranslator&lt;WTF::StringHash&gt;, WTF::StringImpl*&gt;(WTF::StringImpl* const&amp;)
	0.0%	5.0%	WebCore	 WebCore::jsString(JSC::ExecState*, WTF::String const&amp;)
	0.0%	0.1%	WebCore	 WebCore::jsHTMLElementId(JSC::ExecState*, JSC::JSValue, JSC::Identifier const&amp;)
	0.0%	0.0%	WebCore	 WebCore::jsStringOrNull(JSC::ExecState*, WTF::String const&amp;)
	3.5%	3.5%	WebCore	WebCore::JSHTMLElement::getOwnPropertySlot(JSC::JSCell*, JSC::ExecState*, JSC::Identifier const&amp;, JSC::PropertySlot&amp;)
	3.5%	3.5%	JavaScriptCore	JSC::MarkedBlock::sweep(JSC::MarkedBlock::SweepMode)
	3.1%	3.1%	Unknown Library	0x2becb9401640 [23.2KB]
	2.9%	2.9%	JavaScriptCore	JSC::JSValue::toPrimitiveString(JSC::ExecState*) const
	2.7%	2.7%	WebCore	bool WTF::HashTable&lt;WTF::AtomicStringImpl*, WTF::AtomicStringImpl*, WTF::IdentityExtractor, WTF::PtrHash&lt;WTF::AtomicStringImpl*&gt;, WTF::HashTraits&lt;WTF::AtomicStringImpl*&gt;, WTF::HashTraits&lt;WTF::AtomicStringImpl*&gt; &gt;::contains&lt;WTF::IdentityHashTranslator&lt;WTF::PtrHash&lt;WTF::AtomicStringImpl*&gt; &gt;, WTF::AtomicStringImpl*&gt;(WTF::AtomicStringImpl* const&amp;) const
	0.0%	2.7%	WebCore	 WebCore::CSSStyleSelector::hasSelectorForAttribute(WTF::AtomicString const&amp;) const
	0.0%	2.7%	WebCore	  WebCore::Element::recalcStyleIfNeededAfterAttributeChanged(WebCore::Attribute*)
	0.0%	2.7%	WebCore	   WebCore::StyledElement::attributeChanged(WebCore::Attribute*, bool)
	0.0%	2.7%	WebCore	    WebCore::Element::didModifyAttribute(WebCore::Attribute*)
	0.0%	1.8%	WebCore	     WebCore::Element::setAttribute(WebCore::QualifiedName const&amp;, WTF::AtomicString const&amp;)
	0.0%	1.0%	WebCore	     WebCore::Element::setAttribute(WTF::AtomicString const&amp;, WTF::AtomicString const&amp;, int&amp;)
	0.0%	0.0%	WebCore	 WebCore::Element::recalcStyleIfNeededAfterAttributeChanged(WebCore::Attribute*)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>529999</commentid>
    <comment_count>1</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-04 21:47:04 -0800</bug_when>
    <thetext>It seems like just checking needsStyleRecalc() first suffice to improve the performance here.

After adding the check, we get:

	6.1%	6.1%	JavaScriptCore	JSC::IdentifierTable::add(WTF::StringImpl*)
	5.4%	5.4%	JavaScriptCore	WTF::AtomicString::addSlowCase(WTF::StringImpl*)
	4.7%	4.7%	WebCore	WTF::HashTableIterator&lt;WTF::StringImpl*, std::pair&lt;WTF::StringImpl*, JSC::Weak&lt;JSC::JSString&gt; &gt;, WTF::PairFirstExtractor&lt;std::pair&lt;WTF::StringImpl*, JSC::Weak&lt;JSC::JSString&gt; &gt; &gt;, WTF::StringHash, WTF::PairHashTraits&lt;WTF::HashTraits&lt;WTF::StringImpl*&gt;, WTF::HashTraits&lt;JSC::Weak&lt;JSC::JSString&gt; &gt; &gt;, WTF::HashTraits&lt;WTF::StringImpl*&gt; &gt; WTF::HashTable&lt;WTF::StringImpl*, std::pair&lt;WTF::StringImpl*, JSC::Weak&lt;JSC::JSString&gt; &gt;, WTF::PairFirstExtractor&lt;std::pair&lt;WTF::StringImpl*, JSC::Weak&lt;JSC::JSString&gt; &gt; &gt;, WTF::StringHash, WTF::PairHashTraits&lt;WTF::HashTraits&lt;WTF::StringImpl*&gt;, WTF::HashTraits&lt;JSC::Weak&lt;JSC::JSString&gt; &gt; &gt;, WTF::HashTraits&lt;WTF::StringImpl*&gt; &gt;::find&lt;WTF::IdentityHashTranslator&lt;WTF::StringHash&gt;, WTF::StringImpl*&gt;(WTF::StringImpl* const&amp;)
	3.6%	3.6%	Unknown Library	0x5c76577ee160 [11.3KB]
	3.1%	3.1%	WebCore	WebCore::JSHTMLElement::getOwnPropertySlot(JSC::JSCell*, JSC::ExecState*, JSC::Identifier const&amp;, JSC::PropertySlot&amp;)
	3.1%	3.1%	JavaScriptCore	JSC::MarkedBlock::sweep(JSC::MarkedBlock::SweepMode)
	3.0%	3.0%	WebCore	WebCore::jsString(JSC::ExecState*, WTF::String const&amp;)
	2.9%	2.9%	WebCore	WebCore::Element::setAttribute(WTF::AtomicString const&amp;, WTF::AtomicString const&amp;, int&amp;)
	2.9%	2.9%	JavaScriptCore	JSC::JSValue::toPrimitiveString(JSC::ExecState*) const
	2.7%	2.7%	WebCore	WebCore::JSHTMLHeadingElement::getOwnPropertySlot(JSC::JSCell*, JSC::ExecState*, JSC::Identifier const&amp;, JSC::PropertySlot&amp;)
	2.7%	2.7%	WebCore	JSC::JSValue::toString(JSC::ExecState*) const
	2.7%	2.7%	JavaScriptCore	JSC::JSString::resolveRope(JSC::ExecState*) const
	2.6%	2.6%	JavaScriptCore	JSC::JSValue::get(JSC::ExecState*, JSC::Identifier const&amp;, JSC::PropertySlot&amp;) const
	2.4%	2.4%	Unknown Library	0x5c76577b2980 [5.3KB]
	2.4%	2.4%	WebCore	WebCore::Element::idAttributeChanged(WebCore::Attribute*)
	2.3%	2.3%	JavaScriptCore	WTF::StringImpl::lower()
	2.2%	2.2%	WebCore	WebCore::Element::getAttribute(WebCore::QualifiedName const&amp;) const
	2.2%	2.2%	WebCore	WebCore::jsElementPrototypeFunctionSetAttribute(JSC::ExecState*)
	2.0%	2.0%	JavaScriptCore	WTF::AtomicString::lower() const
	1.9%	1.9%	WebCore	WebCore::jsElementPrototypeFunctionGetAttribute(JSC::ExecState*)
	1.9%	1.9%	WebCore	WebCore::StyledElement::attributeChanged(WebCore::Attribute*, bool)
	1.8%	1.8%	JavaScriptCore	JSC::JSString::destroy(JSC::JSCell*)
	1.7%	1.7%	JavaScriptCore	WTF::tryFastMalloc(unsigned long)
	1.7%	1.7%	WebCore	WebCore::Element::setAttribute(WebCore::QualifiedName const&amp;, WTF::AtomicString const&amp;)
	1.6%	1.6%	WebCore	WebCore::JSHTMLAnchorElement::put(JSC::JSCell*, JSC::ExecState*, JSC::Identifier const&amp;, JSC::JSValue, JSC::PutPropertySlot&amp;)
	1.3%	1.3%	Unknown Library	0x5c7657646900 [5.4KB]
	1.3%	1.3%	JavaScriptCore	JSC::JSObject::put(JSC::JSCell*, JSC::ExecState*, JSC::Identifier const&amp;, JSC::JSValue, JSC::PutPropertySlot&amp;)
	1.2%	1.2%	WebCore	WebCore::JSHTMLElement::put(JSC::JSCell*, JSC::ExecState*, JSC::Identifier const&amp;, JSC::JSValue, JSC::PutPropertySlot&amp;)
	1.2%	1.2%	WebCore	WebCore::HTMLAnchorElement::parseMappedAttribute(WebCore::Attribute*)
	1.0%	1.0%	JavaScriptCore	operationGetByVal
	1.0%	1.0%	Unknown Library	0x5c765761a200 [1.9KB]
	1.0%	1.0%	JavaScriptCore	cti_op_put_by_val</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>530005</commentid>
    <comment_count>2</comment_count>
      <attachid>121215</attachid>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-04 22:17:51 -0800</bug_when>
    <thetext>Created attachment 121215
Checks needsStyleRecalc() first</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>530007</commentid>
    <comment_count>3</comment_count>
      <attachid>121215</attachid>
    <who name="Andreas Kling">kling</who>
    <bug_when>2012-01-04 22:19:59 -0800</bug_when>
    <thetext>Comment on attachment 121215
Checks needsStyleRecalc() first

Nice!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>530285</commentid>
    <comment_count>4</comment_count>
      <attachid>121215</attachid>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2012-01-05 08:00:27 -0800</bug_when>
    <thetext>Comment on attachment 121215
Checks needsStyleRecalc() first

Clearing flags on attachment: 121215

Committed r104165: &lt;http://trac.webkit.org/changeset/104165&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>530286</commentid>
    <comment_count>5</comment_count>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2012-01-05 08:00:32 -0800</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>530295</commentid>
    <comment_count>6</comment_count>
    <who name="Antti Koivisto">koivisto</who>
    <bug_when>2012-01-05 08:06:35 -0800</bug_when>
    <thetext>How much did this patch actually improve the performance?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>530779</commentid>
    <comment_count>7</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-05 16:51:43 -0800</bug_when>
    <thetext>It appears that there&apos;s some statistically significant improvement.

with patch:
537.46 runs/s
539.04 runs/s
523.74 runs/s
533.79 runs/s
544.72 runs/s
541.45 runs/s
518.91 runs/s
avg: 534.16
stdev: 9.49 (1.78%)

without patch:
529.29 runs/s
517.19 runs/s
512.61 runs/s
515.45 runs/s
529.42 runs/s
517.45 runs/s
508.90 runs/s
avg: 518.62
stdev: 2.90 (1.52%)

Improvement: 2.91%</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>530798</commentid>
    <comment_count>8</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2012-01-05 17:08:15 -0800</bug_when>
    <thetext>The scores were measured on r103634 (Apple&apos;s mac port); btw, the measured performance gain appears to match the profiling result so we&apos;ve basically eliminated the time spent inside hasSelectorForAttribute :D.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>121215</attachid>
            <date>2012-01-04 22:17:51 -0800</date>
            <delta_ts>2012-01-05 08:00:27 -0800</delta_ts>
            <desc>Checks needsStyleRecalc() first</desc>
            <filename>bug-75569-20120104221750.patch</filename>
            <type>text/plain</type>
            <size>1267</size>
            <attacher name="Ryosuke Niwa">rniwa</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBTb3VyY2UvV2Vi
Q29yZS9DaGFuZ2VMb2cJKHJldmlzaW9uIDEwNDExNikKKysrIFNvdXJjZS9XZWJDb3JlL0NoYW5n
ZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDE1IEBACisyMDEyLTAxLTA0ICBSeW9zdWtl
IE5pd2EgIDxybml3YUB3ZWJraXQub3JnPgorCisgICAgICAgIERPTSBBdHRyaWJ1dGUgdGVzdHMg
b24gRHJvbWFlbyBzcGVuZHMgMi43JSBvZiB0aW1lIGluIGhhc1NlbGVjdG9yRm9yQXR0cmlidXRl
CisgICA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