[webkit-changes] [WebKit/WebKit] 29c1dd: Save some memory by not putting serialized valueID...

Darin Adler noreply at github.com
Mon Jan 30 09:19:05 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 29c1dd85582882ce88551202ced86ad99d31357b
      https://github.com/WebKit/WebKit/commit/29c1dd85582882ce88551202ced86ad99d31357b
  Author: Darin Adler <darin at apple.com>
  Date:   2023-01-30 (Mon, 30 Jan 2023)

  Changed paths:
    M Source/WebCore/css/CSSPrimitiveValue.cpp
    M Source/WebCore/css/CSSPrimitiveValue.h
    M Source/WebCore/css/CSSPrimitiveValueMappings.h
    M Source/WebCore/css/Counter.h
    M Source/WebCore/css/DeprecatedCSSOMCounter.h
    M Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.cpp
    M Source/WebCore/css/parser/CSSPropertyParser.cpp
    M Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp
    M Source/WebCore/css/parser/CSSPropertyParserHelpers.h
    M Source/WebCore/css/process-css-values.py
    M Source/WebCore/style/StyleBuilderCustom.h

  Log Message:
  -----------
  Save some memory by not putting serialized valueID strings into a hash map
https://bugs.webkit.org/show_bug.cgi?id=251340
rdar://104803128

Reviewed by Oriol Brufau.

We can efficiently get the serialized form of CSS value IDs. We should leave them out of the
HashMap that is used to store the serialized form of other CSSPrimitiveValue objects. There
are likely other improvements to make to this machinery, but this saves us some memory right
away, and should not have a measurable performance cost.

While looking over serialization, noticed that the Counter class used to hold counter
content was using CSSPrimitiveValue for no good reason. Turned the class into a struct
that uses AtomString and CSSValueID instead of CSSPrimitiveValue.

* Source/WebCore/css/CSSPrimitiveValue.cpp:
(WebCore::serializedPrimitiveValues): Renamed from cssTextCache. This is not a cache, since
it stores memoized values permanently until the primitive values are deallocated, so we will
not call it a cache.
(WebCore::CSSPrimitiveValue::CSSPrimitiveValue): Updated for change to m_value.number.
(WebCore::CSSPrimitiveValue::~CSSPrimitiveValue): Merged in the code from the cleanup
function. Removed bits of the code that set the value to a cleaned up state, since we don't
need do do that in a destructor. Updated for name change of serializedPrimitiveValues.
(WebCore::CSSPrimitiveValue::cleanup): Deleted.
(WebCore::CSSPrimitiveValue::computeLengthDouble const): Updated for change to m_value.number.
(WebCore::CSSPrimitiveValue::doubleValue const): Ditto.
(WebCore::CSSPrimitiveValue::doubleValueDividingBy100IfPercentage const): Ditto.
(WebCore::CSSPrimitiveValue::isZero const): Ditto.
(WebCore::CSSPrimitiveValue::isPositive const): Ditto.
(WebCore::CSSPrimitiveValue::isNegative const): Ditto.
(WebCore::formatNonfiniteValue): Renamed from formatInfiniteOrNanValue and changed from
a member function to a non-member function. Also tweaked the idiom to make the code a bit
tighter, easier to read, and slightly more efficient for the NaN case.
(WebCore::CSSPrimitiveValue::formatNumberValue const): Use formatNonfiniteValue and
std::isfinite and updated for change to m_value.number.
(WebCore::CSSPrimitiveValue::formatIntegerValue const): Ditto.
(WebCore::CSSPrimitiveValue::unitTypeString): Fixed indentation to match WebKit guidelines.
Sorted cases alphabetically.
(WebCore::serialize): Added. Serializes the Counter struct. Put this here to avoid adding a
Counter.cpp file or adding includes to Counter.h. Use makeString for counter(), but we still need
to use StringBuilder for counters().
(WebCore::CSSPrimitiveValue::serializeInternal const): Renamed from formatNumberForCustomCSSText
since this covers all types, not just numbers. Changed code to use unitTypeString to avoid
repeating all the same suffixes, should still be fast. Sorted cases alphabetically. Use
makeString for CSS_ATTR and CSS_COUNTER_NAME to avoid a little bit of reference count churn for
slightly better performance. Use the new serialize function for CSS_COUNTER.
(WebCore::CSSPrimitiveValue::customCSSText const): Added special cases for CSS_UNKNOWN,
CSS_VALUE_ID, and CSS_PROPERTY_ID since all three can be serialized efficiently without memoizing
the result in the serializedPrimitiveValues map. Use HashMap::add instead of HashMap::set,
making the code slightly tighter.
(WebCore::CSSPrimitiveValue::equals const): Removed some unneeded null checks. Updated for change
to m_value.number.

* Source/WebCore/css/CSSPrimitiveValue.h: Changed Counter from a class to a struct. Removed
cleanup and formatInfiniteOrNanValue. Renamed formatNumberForCustomCSSText to serializeInternal.
Renamed m_value.num to m_value.number.

* Source/WebCore/css/CSSPrimitiveValueMappings.h:
(WebCore::CSSPrimitiveValue::operator ColumnSpan const): Updated for change to m_value.number.

* Source/WebCore/css/Counter.h: Changed from a class to a struct. Use data members instead of
functions, AtomString and CSSValueID instead of CSSPrimitiveValue.

* Source/WebCore/css/DeprecatedCSSOMCounter.h: Use String and CSSValueID instead of
DeprecatedCSSOMPrimitiveValue.

* Source/WebCore/css/DeprecatedCSSOMPrimitiveValue.cpp:
(WebCore::DeprecatedCSSOMPrimitiveValue::getCounterValue const): Updated since we no longer
neeed to pass m_owner to create a DeprecatedCSSOMCounter, and tweaked code style a little.

* Source/WebCore/css/parser/CSSPropertyParser.cpp: Removed unneded include.

* Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:
(WebCore::CSSPropertyParserHelpers::consumeCustomIdentRaw): Added.
(WebCore::CSSPropertyParserHelpers::consumeCustomIdent): Use consumeCustomIdentRaw.
(WebCore::CSSPropertyParserHelpers::consumeCounterContent): Updated for change to Counter.
Use consumeCustomIdentRaw. Made this local to the file.

Source/WebCore/css/parser/CSSPropertyParserHelpers.h: Removed the declaration of
consumeCounterContent. It's better for future maintenance to only declare functions that are used
outside the .cpp file.

* Source/WebCore/css/process-css-values.py:
(GenerationContext): Export nameString. Now used in WebKitLegacy.

* Source/WebCore/style/StyleBuilderCustom.h:
(WebCore::Style::BuilderCustom::applyValueContent): Update counterValue code for the changes
to Counter.

Canonical link: https://commits.webkit.org/259562@main




More information about the webkit-changes mailing list