Title: [164995] trunk/Source/WebCore
- Revision
- 164995
- Author
- commit-qu...@webkit.org
- Date
- 2014-03-03 11:07:53 -0800 (Mon, 03 Mar 2014)
Log Message
Optimize StylePropertiesSet::findPropertyIndex() to improve CSS properties performance
https://bugs.webkit.org/show_bug.cgi?id=129605
Patch by Lorenzo Tilve <lti...@igalia.com> 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):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (164994 => 164995)
--- trunk/Source/WebCore/ChangeLog 2014-03-03 19:02:41 UTC (rev 164994)
+++ trunk/Source/WebCore/ChangeLog 2014-03-03 19:07:53 UTC (rev 164995)
@@ -1,3 +1,42 @@
+2014-03-03 Lorenzo Tilve <lti...@igalia.com>
+
+ 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 Brian Burg <bb...@apple.com>
Unreviewed build fix for Windows after r164986.
Modified: trunk/Source/WebCore/css/StyleProperties.cpp (164994 => 164995)
--- trunk/Source/WebCore/css/StyleProperties.cpp 2014-03-03 19:02:41 UTC (rev 164994)
+++ trunk/Source/WebCore/css/StyleProperties.cpp 2014-03-03 19:07:53 UTC (rev 164995)
@@ -1129,18 +1129,32 @@
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<uint16_t>(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<uint16_t>(propertyID);
+ for (int n = m_propertyVector.size() - 1 ; n >= 0; --n) {
+ if (m_propertyVector.at(n).metadata().m_propertyID == id)
+ return n;
+ }
+
+ return -1;
+}
+
CSSProperty* MutableStyleProperties::findCSSPropertyWithID(CSSPropertyID propertyID)
{
int foundPropertyIndex = findPropertyIndex(propertyID);
Modified: trunk/Source/WebCore/css/StyleProperties.h (164994 => 164995)
--- trunk/Source/WebCore/css/StyleProperties.h 2014-03-03 19:02:41 UTC (rev 164994)
+++ trunk/Source/WebCore/css/StyleProperties.h 2014-03-03 19:07:53 UTC (rev 164995)
@@ -163,6 +163,7 @@
const CSSValue** valueArray() const;
const StylePropertyMetadata* metadataArray() const;
+ int findPropertyIndex(CSSPropertyID) const;
void* m_storage;
@@ -222,6 +223,8 @@
CSSStyleDeclaration* ensureCSSStyleDeclaration();
CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(StyledElement* parentElement);
+ int findPropertyIndex(CSSPropertyID) const;
+
Vector<CSSProperty, 4> m_propertyVector;
private:
@@ -236,6 +239,20 @@
friend class StyleProperties;
};
+TYPE_CASTS_BASE(MutableStyleProperties, StyleProperties, set, set->isMutable(), set.isMutable());
+
+inline MutableStyleProperties* toMutableStyleProperties(const RefPtr<StyleProperties>& set)
+{
+ return toMutableStyleProperties(set.get());
+}
+
+TYPE_CASTS_BASE(ImmutableStyleProperties, StyleProperties, set, !set->isMutable(), !set.isMutable());
+
+inline ImmutableStyleProperties* toImmutableStyleProperties(const RefPtr<StyleProperties>& set)
+{
+ return toImmutableStyleProperties(set.get());
+}
+
inline const StylePropertyMetadata& StyleProperties::PropertyReference::propertyMetadata() const
{
if (m_propertySet.isMutable())
@@ -273,6 +290,13 @@
delete static_cast<ImmutableStyleProperties*>(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
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes