Skip to content
Permalink
Browse files
Give RuleSet a BumpArena and start using it for RuleDataVectors.
<https://webkit.org/b/153169>

Reviewed by Antti Koivisto.

Since RuleSet only supports appending rules and doesn't need to worry about removing them,
it's a great candidate for BumpArena optimizations.

Give each RuleSet its own BumpArena and teach them how to allocate RuleDataVector objects
out of them.

There are more things that can be done here, ideally all the sub-allocations inside RuleSet
that happen via e.g Vector and HashMap would also come out of the BumpArena.

* css/RuleSet.cpp:
(WebCore::RuleSet::RuleSet):
(WebCore::RuleSet::addToRuleSet):
(WebCore::RuleSet::copyShadowPseudoElementRulesFrom):
* css/RuleSet.h:
(WebCore::RuleSet::RuleDataVector::create):
(WebCore::RuleSet::RuleSet): Deleted.


Canonical link: https://commits.webkit.org/171257@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@195173 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Andreas Kling committed Jan 16, 2016
1 parent d7b1917 commit 9d42e7037c2edb4c1aabfba0a37c16fa459f76c8
Showing with 48 additions and 11 deletions.
  1. +24 −0 Source/WebCore/ChangeLog
  2. +7 −2 Source/WebCore/css/RuleSet.cpp
  3. +17 −9 Source/WebCore/css/RuleSet.h
@@ -1,3 +1,27 @@
2016-01-16 Andreas Kling <akling@apple.com>

Give RuleSet a BumpArena and start using it for RuleDataVectors.
<https://webkit.org/b/153169>

Reviewed by Antti Koivisto.

Since RuleSet only supports appending rules and doesn't need to worry about removing them,
it's a great candidate for BumpArena optimizations.

Give each RuleSet its own BumpArena and teach them how to allocate RuleDataVector objects
out of them.

There are more things that can be done here, ideally all the sub-allocations inside RuleSet
that happen via e.g Vector and HashMap would also come out of the BumpArena.

* css/RuleSet.cpp:
(WebCore::RuleSet::RuleSet):
(WebCore::RuleSet::addToRuleSet):
(WebCore::RuleSet::copyShadowPseudoElementRulesFrom):
* css/RuleSet.h:
(WebCore::RuleSet::RuleDataVector::create):
(WebCore::RuleSet::RuleSet): Deleted.

2016-01-16 Simon Fraser <simon.fraser@apple.com>

Fix flakiness of displaylists/layer-dispay-list.html
@@ -183,13 +183,18 @@ static void collectFeaturesFromRuleData(RuleFeatureSet& features, const RuleData
features.uncommonAttributeRules.append(RuleFeature(ruleData.rule(), ruleData.selectorIndex(), ruleData.hasDocumentSecurityOrigin()));
}

RuleSet::RuleSet()
: m_arena(WTF::BumpArena::create())
{
}

void RuleSet::addToRuleSet(AtomicStringImpl* key, AtomRuleMap& map, const RuleData& ruleData)
{
if (!key)
return;
auto& rules = map.add(key, nullptr).iterator->value;
if (!rules)
rules = std::make_unique<RuleDataVector>();
rules = RuleDataVector::create(m_arena.get());
rules->append(ruleData);
}

@@ -399,7 +404,7 @@ bool RuleSet::hasShadowPseudoElementRules() const
void RuleSet::copyShadowPseudoElementRulesFrom(const RuleSet& other)
{
for (auto& keyValuePair : other.m_shadowPseudoElementRules)
m_shadowPseudoElementRules.add(keyValuePair.key, std::make_unique<RuleDataVector>(*keyValuePair.value));
m_shadowPseudoElementRules.add(keyValuePair.key, RuleDataVector::create(m_arena.get(), *keyValuePair.value));

#if ENABLE(VIDEO_TRACK)
// FIXME: We probably shouldn't treat WebVTT as author stylable user agent shadow tree.
@@ -25,6 +25,7 @@
#include "RuleFeature.h"
#include "SelectorCompiler.h"
#include "StyleRule.h"
#include <wtf/BumpArena.h>
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
@@ -158,7 +159,19 @@ class RuleSet {

RuleSet();

typedef Vector<RuleData, 1> RuleDataVector;
class RuleDataVector : public Vector<RuleData, 1> {
WTF_MAKE_BUMPARENA_ALLOCATED;
public:
static std::unique_ptr<RuleDataVector> create(BumpArena& arena)
{
return std::unique_ptr<RuleDataVector>(new (&arena) RuleDataVector);
}
static std::unique_ptr<RuleDataVector> create(BumpArena& arena, const RuleDataVector& other)
{
return std::unique_ptr<RuleDataVector>(new (&arena) RuleDataVector(other));
}
};

typedef HashMap<AtomicStringImpl*, std::unique_ptr<RuleDataVector>> AtomRuleMap;

void addRulesFromSheet(StyleSheetContents&, const MediaQueryEvaluator&, StyleResolver* = 0);
@@ -213,18 +226,13 @@ class RuleSet {
RuleDataVector m_focusPseudoClassRules;
RuleDataVector m_universalRules;
Vector<StyleRulePage*> m_pageRules;
unsigned m_ruleCount;
bool m_autoShrinkToFitEnabled;
unsigned m_ruleCount { 0 };
bool m_autoShrinkToFitEnabled { true };
RuleFeatureSet m_features;
Vector<RuleSetSelectorPair> m_regionSelectorsAndRuleSets;
Ref<BumpArena> m_arena;
};

inline RuleSet::RuleSet()
: m_ruleCount(0)
, m_autoShrinkToFitEnabled(true)
{
}

inline const RuleSet::RuleDataVector* RuleSet::tagRules(AtomicStringImpl* key, bool isHTMLName) const
{
const AtomRuleMap* tagRules;

0 comments on commit 9d42e70

Please sign in to comment.