mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 15:49:11 +00:00
LibWeb: Use invalidation sets to reduce style recalculation
Implements idea described in https://docs.google.com/document/d/1vEW86DaeVs4uQzNFI5R-_xS9TcS1Cs_EUsHRSgCHGu8 Invalidation sets are used to reduce the number of elements marked for style recalculation by collecting metadata from style rules about the dependencies between properties that could affect an element’s style. Currently, this optimization is only applied to style invalidation triggered by class list mutations on an element.
This commit is contained in:
parent
58c78cb003
commit
c5f2a88f69
Notes:
github-actions[bot]
2025-01-19 18:55:55 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: c5f2a88f69
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3292
Reviewed-by: https://github.com/awesomekling
11 changed files with 549 additions and 3 deletions
77
Libraries/LibWeb/CSS/InvalidationSet.h
Normal file
77
Libraries/LibWeb/CSS/InvalidationSet.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/HashTable.h>
|
||||
#include <AK/Traits.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class InvalidationSet {
|
||||
public:
|
||||
struct Property {
|
||||
enum class Type : u8 {
|
||||
InvalidateSelf,
|
||||
InvalidateWholeSubtree,
|
||||
Class,
|
||||
Id,
|
||||
TagName,
|
||||
Attribute,
|
||||
};
|
||||
|
||||
Type type;
|
||||
FlyString name {};
|
||||
|
||||
bool operator==(Property const& other) const = default;
|
||||
};
|
||||
|
||||
void include_all_from(InvalidationSet const& other);
|
||||
|
||||
bool needs_invalidate_self() const { return m_needs_invalidate_self; }
|
||||
void set_needs_invalidate_self() { m_needs_invalidate_self = true; }
|
||||
|
||||
bool needs_invalidate_whole_subtree() const { return m_needs_invalidate_whole_subtree; }
|
||||
void set_needs_invalidate_whole_subtree() { m_needs_invalidate_whole_subtree = true; }
|
||||
|
||||
void set_needs_invalidate_class(FlyString const& name) { m_properties.set({ Property::Type::Class, name }); }
|
||||
void set_needs_invalidate_id(FlyString const& name) { m_properties.set({ Property::Type::Id, name }); }
|
||||
void set_needs_invalidate_tag_name(FlyString const& name) { m_properties.set({ Property::Type::TagName, name }); }
|
||||
void set_needs_invalidate_attribute(FlyString const& name) { m_properties.set({ Property::Type::Attribute, name }); }
|
||||
|
||||
bool is_empty() const;
|
||||
void for_each_property(Function<void(Property const&)> const& callback) const;
|
||||
|
||||
private:
|
||||
bool m_needs_invalidate_self { false };
|
||||
bool m_needs_invalidate_whole_subtree { false };
|
||||
HashTable<Property> m_properties;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
|
||||
template<>
|
||||
struct Traits<Web::CSS::InvalidationSet::Property> : DefaultTraits<String> {
|
||||
static unsigned hash(Web::CSS::InvalidationSet::Property const&);
|
||||
static bool equals(Web::CSS::InvalidationSet::Property const& a, Web::CSS::InvalidationSet::Property const& b) { return a == b; }
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Formatter<Web::CSS::InvalidationSet::Property> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder&, Web::CSS::InvalidationSet::Property const&);
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Formatter<Web::CSS::InvalidationSet> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder&, Web::CSS::InvalidationSet const&);
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue