[webkit-changes] [WebKit/WebKit] a8cb9e: [WebCore] Cache inline styles

Yusuke Suzuki noreply at github.com
Thu Mar 7 10:00:14 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: a8cb9e6d85cf4333473241f52f4de68b7ae352bf
      https://github.com/WebKit/WebKit/commit/a8cb9e6d85cf4333473241f52f4de68b7ae352bf
  Author: Yusuke Suzuki <ysuzuki at apple.com>
  Date:   2024-03-07 (Thu, 07 Mar 2024)

  Changed paths:
    M Source/WebCore/css/CSSBasicShapes.h
    M Source/WebCore/css/CSSCounterValue.h
    M Source/WebCore/css/CSSCrossfadeValue.h
    M Source/WebCore/css/CSSCursorImageValue.h
    M Source/WebCore/css/CSSCustomPropertyValue.h
    M Source/WebCore/css/CSSFilterImageValue.h
    M Source/WebCore/css/CSSFontFaceSrcValue.cpp
    M Source/WebCore/css/CSSFontFaceSrcValue.h
    M Source/WebCore/css/CSSFontPaletteValuesOverrideColorsValue.h
    M Source/WebCore/css/CSSFontStyleRangeValue.h
    M Source/WebCore/css/CSSFontStyleWithAngleValue.h
    M Source/WebCore/css/CSSFontValue.cpp
    M Source/WebCore/css/CSSFontValue.h
    M Source/WebCore/css/CSSGradientValue.h
    M Source/WebCore/css/CSSImageSetOptionValue.h
    M Source/WebCore/css/CSSImageValue.cpp
    M Source/WebCore/css/CSSImageValue.h
    M Source/WebCore/css/CSSOffsetRotateValue.h
    M Source/WebCore/css/CSSPendingSubstitutionValue.h
    M Source/WebCore/css/CSSPrimitiveValue.cpp
    M Source/WebCore/css/CSSPrimitiveValue.h
    M Source/WebCore/css/CSSQuadValue.h
    M Source/WebCore/css/CSSRayValue.h
    M Source/WebCore/css/CSSRectValue.h
    M Source/WebCore/css/CSSReflectValue.h
    M Source/WebCore/css/CSSScrollValue.h
    M Source/WebCore/css/CSSShadowValue.h
    M Source/WebCore/css/CSSValue.cpp
    M Source/WebCore/css/CSSValue.h
    M Source/WebCore/css/CSSValueList.cpp
    M Source/WebCore/css/CSSValueList.h
    M Source/WebCore/css/CSSValuePair.h
    M Source/WebCore/css/CSSVariableReferenceValue.h
    M Source/WebCore/css/CSSViewValue.h
    M Source/WebCore/css/StyleProperties.cpp
    M Source/WebCore/css/StyleProperties.h
    M Source/WebCore/css/StyleSheetContents.cpp
    M Source/WebCore/css/StyleSheetContents.h
    M Source/WebCore/css/parser/CSSParserContext.cpp
    M Source/WebCore/css/parser/CSSParserContext.h
    M Source/WebCore/dom/InlineStyleSheetOwner.cpp

  Log Message:
  -----------
  [WebCore] Cache inline styles
https://bugs.webkit.org/show_bug.cgi?id=270521
rdar://124074797

Reviewed by Antti Koivisto.

CSS in JS is frequently used in the wild. As a result, we can see many
duplicate inline styles randomly, even outside of shadow DOM. Sometimes,
even we use very large strings for inline styles. So we should cache the
inline styles even if it is not inside shadow DOM. This patch adds following
two changes.

1. Caching inline styles for non shadow DOM elements.
2. Adding the mechanism to scan base URL dependecy in CSS rules so that we can disable caching for that case.
   Right now, it is a bit conservative. We disable caching when CSS custom properties exist for example.
3. Originally, we considered using the same mechanism to `setReplacementURLForSubresources` since it needs to
   scan CSSValues too. But it turned out that the implementation is broken and we cannot use it. Since that
   feature also needs to have the correct mechanism to scan CSSValues anyway, this patch implements customVisitChildren
   mechanism to CSSValue, which lists up CSSValue children. So by using this feature, we implement mayDependOnBaseURL
   function by scanning CSSValues. Existing buggy `setReplacementURLForSubresources` / `clearReplacementURLForSubresources` / `traverseSubresources`
   can be rewritten by using this `visitChildren` function. But this patch's intent is not fixing these existing bugs, so
   we separate the fix from this change. (https://bugs.webkit.org/show_bug.cgi?id=270600)
4. We found a bug in StyleSheetContents where we didn't check m_namespaceRules size for `isCacheable()` condition (As a result,
   we observed crashes in some of LayoutTests). This patch fixes it so that we do not say `isCacheable()` => true when there is
   m_namespaceRules.

* Source/WebCore/css/CSSBasicShapes.h:
(WebCore::CSSInsetShapeValue::top const): Deleted.
(WebCore::CSSInsetShapeValue::right const): Deleted.
(WebCore::CSSInsetShapeValue::bottom const): Deleted.
(WebCore::CSSInsetShapeValue::left const): Deleted.
(WebCore::CSSInsetShapeValue::protectedTop const): Deleted.
(WebCore::CSSInsetShapeValue::protectedRight const): Deleted.
(WebCore::CSSInsetShapeValue::protectedBottom const): Deleted.
(WebCore::CSSInsetShapeValue::protectedLeft const): Deleted.
(WebCore::CSSInsetShapeValue::topLeftRadius const): Deleted.
(WebCore::CSSInsetShapeValue::topRightRadius const): Deleted.
(WebCore::CSSInsetShapeValue::bottomRightRadius const): Deleted.
(WebCore::CSSInsetShapeValue::bottomLeftRadius const): Deleted.
(WebCore::CSSInsetShapeValue::protectedTopLeftRadius const): Deleted.
(WebCore::CSSInsetShapeValue::protectedTopRightRadius const): Deleted.
(WebCore::CSSInsetShapeValue::protectedBottomRightRadius const): Deleted.
(WebCore::CSSInsetShapeValue::protectedBottomLeftRadius const): Deleted.
(WebCore::CSSCircleValue::radius const): Deleted.
(WebCore::CSSCircleValue::centerX const): Deleted.
(WebCore::CSSCircleValue::centerY const): Deleted.
(WebCore::CSSCircleValue::protectedRadius const): Deleted.
(WebCore::CSSCircleValue::protectedCenterX const): Deleted.
(WebCore::CSSCircleValue::protectedCenterY const): Deleted.
(WebCore::CSSEllipseValue::radiusX const): Deleted.
(WebCore::CSSEllipseValue::radiusY const): Deleted.
(WebCore::CSSEllipseValue::centerX const): Deleted.
(WebCore::CSSEllipseValue::centerY const): Deleted.
(WebCore::CSSEllipseValue::protectedRadiusX const): Deleted.
(WebCore::CSSEllipseValue::protectedRadiusY const): Deleted.
(WebCore::CSSEllipseValue::protectedCenterX const): Deleted.
(WebCore::CSSEllipseValue::protectedCenterY const): Deleted.
(WebCore::CSSPolygonValue::windRule const): Deleted.
(WebCore::CSSRectShapeValue::top const): Deleted.
(WebCore::CSSRectShapeValue::right const): Deleted.
(WebCore::CSSRectShapeValue::bottom const): Deleted.
(WebCore::CSSRectShapeValue::left const): Deleted.
(WebCore::CSSRectShapeValue::protectedTop const): Deleted.
(WebCore::CSSRectShapeValue::protectedRight const): Deleted.
(WebCore::CSSRectShapeValue::protectedBottom const): Deleted.
(WebCore::CSSRectShapeValue::protectedLeft const): Deleted.
(WebCore::CSSRectShapeValue::topLeftRadius const): Deleted.
(WebCore::CSSRectShapeValue::topRightRadius const): Deleted.
(WebCore::CSSRectShapeValue::bottomRightRadius const): Deleted.
(WebCore::CSSRectShapeValue::bottomLeftRadius const): Deleted.
(WebCore::CSSRectShapeValue::protectedTopLeftRadius const): Deleted.
(WebCore::CSSRectShapeValue::protectedTopRightRadius const): Deleted.
(WebCore::CSSRectShapeValue::protectedBottomRightRadius const): Deleted.
(WebCore::CSSRectShapeValue::protectedBottomLeftRadius const): Deleted.
(WebCore::CSSXywhValue::insetX const): Deleted.
(WebCore::CSSXywhValue::insetY const): Deleted.
(WebCore::CSSXywhValue::width const): Deleted.
(WebCore::CSSXywhValue::height const): Deleted.
(WebCore::CSSXywhValue::protectedInsetX const): Deleted.
(WebCore::CSSXywhValue::protectedInsetY const): Deleted.
(WebCore::CSSXywhValue::protectedWidth const): Deleted.
(WebCore::CSSXywhValue::protectedHeight const): Deleted.
(WebCore::CSSXywhValue::topLeftRadius const): Deleted.
(WebCore::CSSXywhValue::topRightRadius const): Deleted.
(WebCore::CSSXywhValue::bottomRightRadius const): Deleted.
(WebCore::CSSXywhValue::bottomLeftRadius const): Deleted.
(WebCore::CSSXywhValue::protectedTopLeftRadius const): Deleted.
(WebCore::CSSXywhValue::protectedTopRightRadius const): Deleted.
(WebCore::CSSXywhValue::protectedBottomRightRadius const): Deleted.
(WebCore::CSSXywhValue::protectedBottomLeftRadius const): Deleted.
(WebCore::CSSPathValue::pathData const): Deleted.
(WebCore::CSSPathValue::windRule const): Deleted.
* Source/WebCore/css/CSSCounterValue.h:
(WebCore::CSSCounterValue::identifier const): Deleted.
(WebCore::CSSCounterValue::separator const): Deleted.
(WebCore::CSSCounterValue::counterStyle const): Deleted.
* Source/WebCore/css/CSSCrossfadeValue.h:
* Source/WebCore/css/CSSCursorImageValue.h:
* Source/WebCore/css/CSSCustomPropertyValue.h:
* Source/WebCore/css/CSSFilterImageValue.h:
* Source/WebCore/css/CSSFontFaceSrcValue.cpp:
(WebCore::CSSFontFaceSrcResourceValue::customMayDependOnBaseURL const):
* Source/WebCore/css/CSSFontFaceSrcValue.h:
* Source/WebCore/css/CSSFontPaletteValuesOverrideColorsValue.h:
* Source/WebCore/css/CSSFontStyleRangeValue.h:
* Source/WebCore/css/CSSFontStyleWithAngleValue.h:
* Source/WebCore/css/CSSFontValue.cpp:
(WebCore::CSSFontValue::customVisitChildren const):
* Source/WebCore/css/CSSFontValue.h:
* Source/WebCore/css/CSSGradientValue.h:
* Source/WebCore/css/CSSImageSetOptionValue.h:
* Source/WebCore/css/CSSImageValue.cpp:
(WebCore::CSSImageValue::customMayDependOnBaseURL const):
* Source/WebCore/css/CSSImageValue.h:
* Source/WebCore/css/CSSOffsetRotateValue.h:
* Source/WebCore/css/CSSPendingSubstitutionValue.h:
(WebCore::CSSPendingSubstitutionValue::customVisitChildren const):
* Source/WebCore/css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::customVisitChildren const):
* Source/WebCore/css/CSSPrimitiveValue.h:
* Source/WebCore/css/CSSRayValue.h:
* Source/WebCore/css/CSSReflectValue.h:
* Source/WebCore/css/CSSScrollValue.h:
* Source/WebCore/css/CSSShadowValue.h:
* Source/WebCore/css/CSSValue.cpp:
(WebCore::CSSValue::visitChildren const):
(WebCore::CSSValue::mayDependOnBaseURL const):
* Source/WebCore/css/CSSValue.h:
(WebCore::CSSValue::customMayDependOnBaseURL const):
(WebCore::CSSValue::customVisitChildren const):
* Source/WebCore/css/CSSValueList.h:
(WebCore::CSSValueContainingVector::customVisitChildren const):
* Source/WebCore/css/CSSValuePair.h:
(WebCore::CSSValuePair::customVisitChildren const):
* Source/WebCore/css/CSSVariableReferenceValue.h:
(WebCore::CSSVariableReferenceValue::customMayDependOnBaseURL const):
* Source/WebCore/css/CSSViewValue.h:
* Source/WebCore/css/StyleProperties.cpp:
(WebCore::StyleProperties::mayDependOnBaseURL const):
* Source/WebCore/css/StyleProperties.h:
* Source/WebCore/css/StyleSheetContents.cpp:
(WebCore::StyleSheetContents::StyleSheetContents):
(WebCore::StyleSheetContents::isCacheable const):
(WebCore::StyleSheetContents::isCacheableAndNoBaseURLDependency const):
(WebCore::StyleSheetContents::mayDependOnBaseURL const):
* Source/WebCore/css/StyleSheetContents.h:
* Source/WebCore/css/parser/CSSParserContext.cpp:
(WebCore::mayDependOnBaseURL):
* Source/WebCore/css/parser/CSSParserContext.h:
* Source/WebCore/dom/InlineStyleSheetOwner.cpp:
(WebCore::InlineStyleSheetOwner::createSheet):
(WebCore::makeStyleSheetContentsCacheKey): Deleted.

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



To unsubscribe from these emails, change your notification settings at https://github.com/WebKit/WebKit/settings/notifications


More information about the webkit-changes mailing list