Changeset 256423 in webkit


Ignore:
Timestamp:
Feb 11, 2020 8:11:04 PM (4 years ago)
Author:
ysuzuki@apple.com
Message:

Compress ImmutableStyleProperties by using PackedPtr
https://bugs.webkit.org/show_bug.cgi?id=207604

Reviewed by Mark Lam.

ImmutableStyleProperties is kept so long and consumes enough memory.
We already attempted to compact it by storing CSSProperty's members separately.
But we can compact further by using PackedPtr. This patch makes,

  1. Use PackedPtr for CSSValue* in ImmutableStyleProperties so that we can cut some bytes
  2. Reorder CSSValue* and StylePropertyMetadata arrays since StylePropertyMetadata requires alignment while PackedPtr<CSSValue> is not.

No behavior change.

  • css/StyleProperties.cpp:

(WebCore::sizeForImmutableStylePropertiesWithPropertyCount):
(WebCore::ImmutableStyleProperties::ImmutableStyleProperties):
(WebCore::ImmutableStyleProperties::~ImmutableStyleProperties):
(WebCore::ImmutableStyleProperties::findCustomPropertyIndex const):

  • css/StyleProperties.h:

(WebCore::ImmutableStyleProperties::valueArray const):
(WebCore::ImmutableStyleProperties::metadataArray const):
(WebCore::ImmutableStyleProperties::propertyAt const):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r256421 r256423  
     12020-02-11  Yusuke Suzuki  <ysuzuki@apple.com>
     2
     3        Compress ImmutableStyleProperties by using PackedPtr
     4        https://bugs.webkit.org/show_bug.cgi?id=207604
     5
     6        Reviewed by Mark Lam.
     7
     8        ImmutableStyleProperties is kept so long and consumes enough memory.
     9        We already attempted to compact it by storing CSSProperty's members separately.
     10        But we can compact further by using PackedPtr. This patch makes,
     11
     12            1. Use PackedPtr for CSSValue* in ImmutableStyleProperties so that we can cut some bytes
     13            2. Reorder CSSValue* and StylePropertyMetadata arrays since StylePropertyMetadata requires alignment while PackedPtr<CSSValue> is not.
     14
     15        No behavior change.
     16
     17        * css/StyleProperties.cpp:
     18        (WebCore::sizeForImmutableStylePropertiesWithPropertyCount):
     19        (WebCore::ImmutableStyleProperties::ImmutableStyleProperties):
     20        (WebCore::ImmutableStyleProperties::~ImmutableStyleProperties):
     21        (WebCore::ImmutableStyleProperties::findCustomPropertyIndex const):
     22        * css/StyleProperties.h:
     23        (WebCore::ImmutableStyleProperties::valueArray const):
     24        (WebCore::ImmutableStyleProperties::metadataArray const):
     25        (WebCore::ImmutableStyleProperties::propertyAt const):
     26
    1272020-02-11  Carlos Alberto Lopez Perez  <clopez@igalia.com>
    228
  • trunk/Source/WebCore/css/StyleProperties.cpp

    r253987 r256423  
    5656static size_t sizeForImmutableStylePropertiesWithPropertyCount(unsigned count)
    5757{
    58     return sizeof(ImmutableStyleProperties) - sizeof(void*) + sizeof(CSSValue*) * count + sizeof(StylePropertyMetadata) * count;
     58    return sizeof(ImmutableStyleProperties) - sizeof(void*) + sizeof(StylePropertyMetadata) * count + sizeof(PackedPtr<const CSSValue>) * count;
    5959}
    6060
     
    9595{
    9696    StylePropertyMetadata* metadataArray = const_cast<StylePropertyMetadata*>(this->metadataArray());
    97     CSSValue** valueArray = const_cast<CSSValue**>(this->valueArray());
     97    PackedPtr<CSSValue>* valueArray = bitwise_cast<PackedPtr<CSSValue>*>(this->valueArray());
    9898    for (unsigned i = 0; i < length; ++i) {
    9999        metadataArray[i] = properties[i].metadata();
    100         valueArray[i] = properties[i].value();
    101         valueArray[i]->ref();
     100        auto* value = properties[i].value();
     101        valueArray[i] = value;
     102        value->ref();
    102103    }
    103104}
     
    105106ImmutableStyleProperties::~ImmutableStyleProperties()
    106107{
    107     CSSValue** valueArray = const_cast<CSSValue**>(this->valueArray());
     108    PackedPtr<CSSValue>* valueArray = bitwise_cast<PackedPtr<CSSValue>*>(this->valueArray());
    108109    for (unsigned i = 0; i < m_arraySize; ++i)
    109110        valueArray[i]->deref();
     
    14721473        if (metadataArray()[n].m_propertyID == CSSPropertyCustom) {
    14731474            // We found a custom property. See if the name matches.
    1474             if (!valueArray()[n])
     1475            auto* value = valueArray()[n].get();
     1476            if (!value)
    14751477                continue;
    1476             if (downcast<CSSCustomPropertyValue>(*valueArray()[n]).name() == propertyName)
     1478            if (downcast<CSSCustomPropertyValue>(*value).name() == propertyName)
    14771479                return n;
    14781480        }
  • trunk/Source/WebCore/css/StyleProperties.h

    r253987 r256423  
    191191    PropertyReference propertyAt(unsigned index) const;
    192192
    193     const CSSValue** valueArray() const;
    194     const StylePropertyMetadata* metadataArray() const;
    195193    int findPropertyIndex(CSSPropertyID) const;
    196194    int findCustomPropertyIndex(const String& propertyName) const;
     
    199197
    200198private:
     199    PackedPtr<const CSSValue>* valueArray() const;
     200    const StylePropertyMetadata* metadataArray() const;
    201201    ImmutableStyleProperties(const CSSProperty*, unsigned count, CSSParserMode);
    202202};
    203203
    204 inline const CSSValue** ImmutableStyleProperties::valueArray() const
    205 {
    206     return reinterpret_cast<const CSSValue**>(const_cast<const void**>((&(this->m_storage))));
     204inline PackedPtr<const CSSValue>* ImmutableStyleProperties::valueArray() const
     205{
     206    return bitwise_cast<PackedPtr<const CSSValue>*>(bitwise_cast<const uint8_t*>(metadataArray()) + (m_arraySize * sizeof(StylePropertyMetadata)));
    207207}
    208208
    209209inline const StylePropertyMetadata* ImmutableStyleProperties::metadataArray() const
    210210{
    211     return reinterpret_cast_ptr<const StylePropertyMetadata*>(&reinterpret_cast_ptr<const char*>(&(this->m_storage))[m_arraySize * sizeof(CSSValue*)]);
     211    return reinterpret_cast<const StylePropertyMetadata*>(const_cast<const void**>((&(this->m_storage))));
    212212}
    213213
     
    290290inline ImmutableStyleProperties::PropertyReference ImmutableStyleProperties::propertyAt(unsigned index) const
    291291{
    292     return PropertyReference(metadataArray()[index], valueArray()[index]);
     292    return PropertyReference(metadataArray()[index], valueArray()[index].get());
    293293}
    294294
Note: See TracChangeset for help on using the changeset viewer.