Skip to content

Commit

Permalink
Merge r164995 - Optimize StylePropertiesSet::findPropertyIndex() to i…
Browse files Browse the repository at this point in the history
…mprove CSS properties performance

https://bugs.webkit.org/show_bug.cgi?id=129605

Patch by Lorenzo Tilve <ltilve@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):
  • Loading branch information
ltilve authored and carlosgcampos committed Mar 6, 2014
1 parent 4ca3e4f commit 63bab91
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
39 changes: 39 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,42 @@
2014-03-03 Lorenzo Tilve <ltilve@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 Tomas Popela <tpopela@redhat.com>

[GTK] webkit_dom_range_compare_boundary_points fails when 0 is passed as how parameter
Expand Down
20 changes: 17 additions & 3 deletions Source/WebCore/css/StyleProperties.cpp
Expand Up @@ -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<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;
}

Expand Down
24 changes: 24 additions & 0 deletions Source/WebCore/css/StyleProperties.h
Expand Up @@ -163,6 +163,7 @@ class ImmutableStyleProperties : public StyleProperties {

const CSSValue** valueArray() const;
const StylePropertyMetadata* metadataArray() const;
int findPropertyIndex(CSSPropertyID) const;

void* m_storage;

Expand Down Expand Up @@ -222,6 +223,8 @@ class MutableStyleProperties : public StyleProperties {
CSSStyleDeclaration* ensureCSSStyleDeclaration();
CSSStyleDeclaration* ensureInlineCSSStyleDeclaration(StyledElement* parentElement);

int findPropertyIndex(CSSPropertyID) const;

Vector<CSSProperty, 4> m_propertyVector;

private:
Expand All @@ -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<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())
Expand Down Expand Up @@ -273,6 +290,13 @@ inline void StyleProperties::deref()
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

0 comments on commit 63bab91

Please sign in to comment.