From 63bab91e6051158ac4df2b2fa52fe05b5546baac Mon Sep 17 00:00:00 2001 From: Lorenzo Tilve Date: Thu, 6 Mar 2014 14:00:03 +0000 Subject: [PATCH] Merge r164995 - Optimize StylePropertiesSet::findPropertyIndex() to improve CSS properties performance https://bugs.webkit.org/show_bug.cgi?id=129605 Patch by Lorenzo Tilve on 2014-03-03 Reviewed by Andreas Kling. Merged from Blink (patch by Mikhail Pozdnyakov): https://src.chromium.org/viewvc/blink?view=revision&revision=167325 Avoid checking whether 'StylePropertiesSet' is mutable and accesing directly to its data members to achieve performance improvements Before the optimization applied: mean: 3064.8337171934063 runs/s median: 3097.5899379343855 runs/s stdev: 66.89274074044187 runs/s min: 2891.7479324362585 runs/s max: 3113.288683440125 runs/s After the optimization applied: mean: 3343.8356114138105 runs/s median: 3356.25682957446 runs/s stdev: 36.297533087489036 runs/s min: 3238.5468032264243 runs/s max: 3368.664837531425 runs/s Performance gain for the average value is approx. 9.1%, in the range of the 10% - 8.2% for the min and max measured values (Linux desktop x64). * css/StyleProperties.cpp: (WebCore::ImmutableStyleProperties::findPropertyIndex): (WebCore::MutableStyleProperties::findPropertyIndex): * css/StyleProperties.h: (WebCore::toMutableStyleProperties): (WebCore::toImmutableStyleProperties): (WebCore::StyleProperties::findPropertyIndex): --- Source/WebCore/ChangeLog | 39 ++++++++++++++++++++++++++ Source/WebCore/css/StyleProperties.cpp | 20 +++++++++++-- Source/WebCore/css/StyleProperties.h | 24 ++++++++++++++++ 3 files changed, 80 insertions(+), 3 deletions(-) diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 2d8dcb7ecada..ee625dede439 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,42 @@ +2014-03-03 Lorenzo Tilve + + Optimize StylePropertiesSet::findPropertyIndex() to improve CSS properties performance + https://bugs.webkit.org/show_bug.cgi?id=129605 + + Reviewed by Andreas Kling. + + Merged from Blink (patch by Mikhail Pozdnyakov): + https://src.chromium.org/viewvc/blink?view=revision&revision=167325 + + Avoid checking whether 'StylePropertiesSet' is mutable and accesing directly to its + data members to achieve performance improvements + + Before the optimization applied: + mean: 3064.8337171934063 runs/s + median: 3097.5899379343855 runs/s + stdev: 66.89274074044187 runs/s + min: 2891.7479324362585 runs/s + max: 3113.288683440125 runs/s + + After the optimization applied: + mean: 3343.8356114138105 runs/s + median: 3356.25682957446 runs/s + stdev: 36.297533087489036 runs/s + min: 3238.5468032264243 runs/s + max: 3368.664837531425 runs/s + + Performance gain for the average value is approx. 9.1%, in the + range of the 10% - 8.2% for the min and max measured + values (Linux desktop x64). + + * css/StyleProperties.cpp: + (WebCore::ImmutableStyleProperties::findPropertyIndex): + (WebCore::MutableStyleProperties::findPropertyIndex): + * css/StyleProperties.h: + (WebCore::toMutableStyleProperties): + (WebCore::toImmutableStyleProperties): + (WebCore::StyleProperties::findPropertyIndex): + 2014-03-03 Tomas Popela [GTK] webkit_dom_range_compare_boundary_points fails when 0 is passed as how parameter diff --git a/Source/WebCore/css/StyleProperties.cpp b/Source/WebCore/css/StyleProperties.cpp index 7245fab85680..bb3570f73d17 100644 --- a/Source/WebCore/css/StyleProperties.cpp +++ b/Source/WebCore/css/StyleProperties.cpp @@ -1129,15 +1129,29 @@ bool MutableStyleProperties::removePropertiesInSet(const CSSPropertyID* set, uns return changed; } -int StyleProperties::findPropertyIndex(CSSPropertyID propertyID) const +int ImmutableStyleProperties::findPropertyIndex(CSSPropertyID propertyID) const { // Convert here propertyID into an uint16_t to compare it with the metadata's m_propertyID to avoid // the compiler converting it to an int multiple times in the loop. uint16_t id = static_cast(propertyID); - for (int n = propertyCount() - 1 ; n >= 0; --n) { - if (id == propertyAt(n).propertyMetadata().m_propertyID) + for (int n = m_arraySize - 1 ; n >= 0; --n) { + if (metadataArray()[n].m_propertyID == id) return n; } + + return -1; +} + +int MutableStyleProperties::findPropertyIndex(CSSPropertyID propertyID) const +{ + // Convert here propertyID into an uint16_t to compare it with the metadata's m_propertyID to avoid + // the compiler converting it to an int multiple times in the loop. + uint16_t id = static_cast(propertyID); + for (int n = m_propertyVector.size() - 1 ; n >= 0; --n) { + if (m_propertyVector.at(n).metadata().m_propertyID == id) + return n; + } + return -1; } diff --git a/Source/WebCore/css/StyleProperties.h b/Source/WebCore/css/StyleProperties.h index 70024a33f579..f958c84273cf 100644 --- a/Source/WebCore/css/StyleProperties.h +++ b/Source/WebCore/css/StyleProperties.h @@ -163,6 +163,7 @@ class ImmutableStyleProperties : public StyleProperties { const CSSValue** valueArray() const; const StylePropertyMetadata* metadataArray() const; + int findPropertyIndex(CSSPropertyID) const; void* m_storage; @@ -222,6 +223,8 @@ class MutableStyleProperties : public StyleProperties { CSSStyleDeclaration* ensureCSSStyleDeclaration(); CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(StyledElement* parentElement); + int findPropertyIndex(CSSPropertyID) const; + Vector m_propertyVector; private: @@ -236,6 +239,20 @@ class MutableStyleProperties : public StyleProperties { friend class StyleProperties; }; +TYPE_CASTS_BASE(MutableStyleProperties, StyleProperties, set, set->isMutable(), set.isMutable()); + +inline MutableStyleProperties* toMutableStyleProperties(const RefPtr& set) +{ + return toMutableStyleProperties(set.get()); +} + +TYPE_CASTS_BASE(ImmutableStyleProperties, StyleProperties, set, !set->isMutable(), !set.isMutable()); + +inline ImmutableStyleProperties* toImmutableStyleProperties(const RefPtr& set) +{ + return toImmutableStyleProperties(set.get()); +} + inline const StylePropertyMetadata& StyleProperties::PropertyReference::propertyMetadata() const { if (m_propertySet.isMutable()) @@ -273,6 +290,13 @@ inline void StyleProperties::deref() delete static_cast(this); } +inline int StyleProperties::findPropertyIndex(CSSPropertyID propertyID) const +{ + if (m_isMutable) + return toMutableStyleProperties(this)->findPropertyIndex(propertyID); + return toImmutableStyleProperties(this)->findPropertyIndex(propertyID); +} + } // namespace WebCore #endif // StyleProperties_h