Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save memory when StyleRule doesn't need nesting support #10044

Merged
merged 1 commit into from Feb 14, 2023

Conversation

mdubet
Copy link
Contributor

@mdubet mdubet commented Feb 13, 2023

9db1de4

Save memory when StyleRule doesn't need nesting support
https://bugs.webkit.org/show_bug.cgi?id=252176
rdar://105399781

Reviewed by Antti Koivisto.

Support for CSS Nesting has added 2 members to the StyleRule class
(the resolved selector list, and the list of children rules),
which created a memory regression of Membuster.

This patch creates a separate StyleWithNestingRule to be used when we actually
need the CSS Nesting feature (which is determined at parsing time).

When we don't need the CSS Nesting feature, it has exactly zero memory cost.

* Source/WebCore/bindings/js/JSCSSRuleCustom.cpp:
(WebCore::toJSNewlyCreated):
* Source/WebCore/css/CSSSelectorList.cpp:
(WebCore::CSSSelectorList::hasExplicitNestingParent const):
* Source/WebCore/css/CSSSelectorList.h:
* Source/WebCore/css/CSSStyleRule.cpp:
(WebCore::CSSStyleRule::CSSStyleRule):
(WebCore::CSSStyleRule::nestedRules const):
(WebCore::CSSStyleRule::cssText const):
(WebCore::CSSStyleRule::length const):
(WebCore::CSSStyleRule::item const):
* Source/WebCore/css/CSSStyleRule.h:
* Source/WebCore/css/StyleRule.cpp:
(WebCore::StyleRuleBase::visitDerived):
(WebCore::StyleRuleBase::createCSSOMWrapper const):
(WebCore::StyleRule::StyleRule):
(WebCore::StyleRule::create):
(WebCore::StyleRule::createForSplitting):
(WebCore::StyleRule::resolvedSelectorList const):
(WebCore::StyleRuleWithNesting::create):
(WebCore::StyleRuleWithNesting::StyleRuleWithNesting):
(WebCore::StyleRuleWithNesting::setResolvedSelectorList const):
(WebCore::StyleRuleGroup::StyleRuleGroup):
(WebCore::StyleRuleRareData::createIfNeeded): Deleted.
(WebCore::StyleRule::rareData const): Deleted.
(WebCore::StyleRule::setNestedRules): Deleted.
(WebCore::StyleRule::setResolvedSelectorList const): Deleted.
(WebCore::emptyRuleVector): Deleted.
(WebCore::StyleRule::nestedRules const): Deleted.
* Source/WebCore/css/StyleRule.h:
(WebCore::StyleRuleBase::isStyleRule const):
(WebCore::StyleRuleBase::isStyleRuleWithNesting const):
(WebCore::StyleRuleBase::setType):
(isType):
(WebCore::StyleRuleRareData::createIfNeeded): Deleted.
* Source/WebCore/css/StyleRuleType.h:
* Source/WebCore/css/StyleSheetContents.cpp:
(WebCore::StyleSheetContents::traverseSubresources const):
* Source/WebCore/css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::createNestingParentRule):
(WebCore::CSSParserImpl::consumeStyleRule):
* Source/WebCore/css/parser/CSSParserImpl.h:
* Source/WebCore/inspector/InspectorStyleSheet.cpp:
(WebCore::flatteningStrategyForStyleRuleType):
* Source/WebCore/style/RuleSetBuilder.cpp:
(WebCore::Style::RuleSetBuilder::addChildRule):
(WebCore::Style::RuleSetBuilder::populateStyleRuleResolvedSelectorList):
(WebCore::Style::RuleSetBuilder::addStyleRuleWithSelectorList):
(WebCore::Style::RuleSetBuilder::addStyleRule):
* Source/WebCore/style/RuleSetBuilder.h:

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

77fd382

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style βœ… πŸ›  ios βœ… πŸ›  mac βœ… πŸ›  wpe βœ… πŸ›  wincairo
βœ… πŸ§ͺ bindings βœ… πŸ›  ios-sim βœ… πŸ›  mac-AS-debug βœ… πŸ›  gtk
βœ… πŸ§ͺ webkitperl βœ… πŸ§ͺ ios-wk2 βœ… πŸ§ͺ api-mac βœ… πŸ§ͺ gtk-wk2
βœ… πŸ§ͺ api-ios βœ… πŸ§ͺ mac-wk1   πŸ§ͺ api-gtk
βœ… πŸ›  πŸ§ͺ jsc βœ… πŸ›  tv βœ… πŸ§ͺ mac-wk2 βœ… πŸ›  jsc-armv7
βœ… πŸ›  πŸ§ͺ jsc-arm64 βœ… πŸ›  tv-sim βœ… πŸ§ͺ mac-AS-debug-wk2   πŸ§ͺ jsc-armv7-tests
βœ… πŸ›  watch βœ… πŸ§ͺ mac-wk2-stress βœ… πŸ›  jsc-mips
βœ… πŸ›  πŸ§ͺ merge βœ… πŸ›  watch-sim βœ… πŸ§ͺ jsc-mips-tests

@mdubet mdubet self-assigned this Feb 13, 2023
@mdubet mdubet added the WebCore Misc. For miscellaneous bugs in the WebCore framework (and not JavaScriptCore or WebKit). label Feb 13, 2023
Source/WebCore/css/StyleRule.h Outdated Show resolved Hide resolved
@mdubet mdubet added the merge-queue Applied to send a pull request to merge-queue label Feb 14, 2023
https://bugs.webkit.org/show_bug.cgi?id=252176
rdar://105399781

Reviewed by Antti Koivisto.

Support for CSS Nesting has added 2 members to the StyleRule class
(the resolved selector list, and the list of children rules),
which created a memory regression of Membuster.

This patch creates a separate StyleWithNestingRule to be used when we actually
need the CSS Nesting feature (which is determined at parsing time).

When we don't need the CSS Nesting feature, it has exactly zero memory cost.

* Source/WebCore/bindings/js/JSCSSRuleCustom.cpp:
(WebCore::toJSNewlyCreated):
* Source/WebCore/css/CSSSelectorList.cpp:
(WebCore::CSSSelectorList::hasExplicitNestingParent const):
* Source/WebCore/css/CSSSelectorList.h:
* Source/WebCore/css/CSSStyleRule.cpp:
(WebCore::CSSStyleRule::CSSStyleRule):
(WebCore::CSSStyleRule::nestedRules const):
(WebCore::CSSStyleRule::cssText const):
(WebCore::CSSStyleRule::length const):
(WebCore::CSSStyleRule::item const):
* Source/WebCore/css/CSSStyleRule.h:
* Source/WebCore/css/StyleRule.cpp:
(WebCore::StyleRuleBase::visitDerived):
(WebCore::StyleRuleBase::createCSSOMWrapper const):
(WebCore::StyleRule::StyleRule):
(WebCore::StyleRule::create):
(WebCore::StyleRule::createForSplitting):
(WebCore::StyleRule::resolvedSelectorList const):
(WebCore::StyleRuleWithNesting::create):
(WebCore::StyleRuleWithNesting::StyleRuleWithNesting):
(WebCore::StyleRuleWithNesting::setResolvedSelectorList const):
(WebCore::StyleRuleGroup::StyleRuleGroup):
(WebCore::StyleRuleRareData::createIfNeeded): Deleted.
(WebCore::StyleRule::rareData const): Deleted.
(WebCore::StyleRule::setNestedRules): Deleted.
(WebCore::StyleRule::setResolvedSelectorList const): Deleted.
(WebCore::emptyRuleVector): Deleted.
(WebCore::StyleRule::nestedRules const): Deleted.
* Source/WebCore/css/StyleRule.h:
(WebCore::StyleRuleBase::isStyleRule const):
(WebCore::StyleRuleBase::isStyleRuleWithNesting const):
(WebCore::StyleRuleBase::setType):
(isType):
(WebCore::StyleRuleRareData::createIfNeeded): Deleted.
* Source/WebCore/css/StyleRuleType.h:
* Source/WebCore/css/StyleSheetContents.cpp:
(WebCore::StyleSheetContents::traverseSubresources const):
* Source/WebCore/css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::createNestingParentRule):
(WebCore::CSSParserImpl::consumeStyleRule):
* Source/WebCore/css/parser/CSSParserImpl.h:
* Source/WebCore/inspector/InspectorStyleSheet.cpp:
(WebCore::flatteningStrategyForStyleRuleType):
* Source/WebCore/style/RuleSetBuilder.cpp:
(WebCore::Style::RuleSetBuilder::addChildRule):
(WebCore::Style::RuleSetBuilder::populateStyleRuleResolvedSelectorList):
(WebCore::Style::RuleSetBuilder::addStyleRuleWithSelectorList):
(WebCore::Style::RuleSetBuilder::addStyleRule):
* Source/WebCore/style/RuleSetBuilder.h:

Canonical link: https://commits.webkit.org/260281@main
@webkit-commit-queue
Copy link
Collaborator

Committed 260281@main (9db1de4): https://commits.webkit.org/260281@main

Reviewed commits have been landed. Closing PR #10044 and removing active labels.

@webkit-early-warning-system webkit-early-warning-system merged commit 9db1de4 into WebKit:main Feb 14, 2023
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebCore Misc. For miscellaneous bugs in the WebCore framework (and not JavaScriptCore or WebKit).
Projects
None yet
4 participants