Changing id, className, or attribute should invalidate distribution
authorshinyak@chromium.org <shinyak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2012 06:50:15 +0000 (06:50 +0000)
committershinyak@chromium.org <shinyak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2012 06:50:15 +0000 (06:50 +0000)
commitb2b39f1d26d709d9d27b19b05e357643a2c74225
treeeafd66402edb9741bdd42425f3f97514177276c0
parent771ed4f26944cdeb2865fa25937cf217859b6a29
Changing id, className, or attribute should invalidate distribution
https://bugs.webkit.org/show_bug.cgi?id=100738

Reviewed by Dimitri Glazkov.

PerformanceTests:

Added test code to modify id/class/attribute.

* DOM/ModifyAttribute.html: Added.
* DOM/resources/dom-perf/modify-attribute.js: Added.
(ModifyAttribute.CreateElementToSetUp):
(ModifyAttribute.ModifyId):
(ModifyAttribute.ModifyClass):
(ModifyAttribute.ModifyTitle):

Source/WebCore:

When id, className, or attribute is changed, we might have to invalidate distribution.
However, we don't want to do useless invalidation. So we consult with the RuleFeatureSet of ElementShadow,
and invalidate distribution only if necessary.

When className is changed, we can share a lot of code between invalidating distribution and invalidating style.
So we made checkNeedsStyleInvalidationForClassChange a template method, and share it.

Also we've measured how this patch makes changing attribute slow. By converting checkNeedsStyleInvalidationForClassChange
to template, actually this improves the performance of changing attribute code. I've measured each code 3 times.

DOM/ModifyAttribute.html
Before this patch:
        median  stdev  min      max    [ms]
  1st   115.62   0.67  114.75   117.00
  2nd   115.08   1.13  113.25   117.58
  3rd   114.75   1.16  113.42   117.83

After this patch:
        median  stdev  min      max    [ms]
  1st   102.55   0.95  101.25   104.50
  2nd   103.10   0.86  102.20   100.95
  3rd   103.30   1.05  102.10   106.65

Tests: fast/dom/shadow/distribution-attribute-modified.html
       fast/dom/shadow/distribution-className-modified.html
       fast/dom/shadow/distribution-id-modified.html
       fast/dom/shadow/reprojection-attribute-modified.html
       fast/dom/shadow/reprojection-className-modified.html
       fast/dom/shadow/reprojection-id-modified.html

* dom/Element.cpp:
(WebCore::Element::attributeChanged):
(WebCore::HasSelectorForClassStyleFunctor::HasSelectorForClassStyleFunctor):
(HasSelectorForClassStyleFunctor):
(WebCore::HasSelectorForClassStyleFunctor::operator()): Returns true if StyleResolver::hasSelectorForClass returns true.
(WebCore):
(WebCore::HasSelectorForClassDistributionFunctor::HasSelectorForClassDistributionFunctor):
(HasSelectorForClassDistributionFunctor):
(WebCore::HasSelectorForClassDistributionFunctor::operator()): Returns true if ElementShadow::hasSelectorForClass returns true.
(WebCore::checkFunctorForClassChange):
(WebCore::checkNeedsStyleInvalidationForClassChange): Extacted the implementation to checkFunctorForClassChange.
(WebCore::checkNeedsDistributionInvalidationForClassChange):
(WebCore::Element::classAttributeChanged):

LayoutTests:

We have test cases that id/class/attribute is changed, and thier reprojection cases.

* fast/dom/shadow/distribution-attribute-modified-expected.html: Added.
* fast/dom/shadow/distribution-attribute-modified.html: Added.
* fast/dom/shadow/distribution-className-modified-expected.html: Added.
* fast/dom/shadow/distribution-className-modified.html: Added.
* fast/dom/shadow/distribution-id-modified-expected.html: Added.
* fast/dom/shadow/distribution-id-modified.html: Added.
* fast/dom/shadow/reprojection-attribute-modified-expected.html: Added.
* fast/dom/shadow/reprojection-attribute-modified.html: Added.
* fast/dom/shadow/reprojection-className-modified-expected.html: Added.
* fast/dom/shadow/reprojection-className-modified.html: Added.
* fast/dom/shadow/reprojection-id-modified-expected.html: Added.
* fast/dom/shadow/reprojection-id-modified.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@134367 268f45cc-cd09-0410-ab3c-d52691b4dbfc
18 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/dom/shadow/distribution-attribute-modified-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/distribution-attribute-modified.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/distribution-className-modified-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/distribution-className-modified.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/distribution-id-modified-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/distribution-id-modified.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/reprojection-attribute-modified-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/reprojection-attribute-modified.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/reprojection-className-modified-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/reprojection-className-modified.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/reprojection-id-modified-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/shadow/reprojection-id-modified.html [new file with mode: 0644]
PerformanceTests/ChangeLog
PerformanceTests/DOM/ModifyAttribute.html [new file with mode: 0644]
PerformanceTests/DOM/resources/dom-perf/modify-attribute.js [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/dom/Element.cpp