mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-23 01:12:45 +00:00
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This change converts `Node::invalidate_style()` (invalidation sets overload) from eagerly doing tree traversal that marks elements affected by invalidation set to instead adding "pending invalidation sets" into `StyleInvalidator`, processing of which is deferred until the next `update_style()`. By doing that we sometimes substantially reduce amount of work done performing tree traversal that marks elements for style recalculation. Improves performance on Discord, were according to my measurements we were previously spending 20% of time in style invalidation, but now it's down to <1%.
39 lines
1.2 KiB
C++
39 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibGC/CellAllocator.h>
|
|
#include <LibWeb/CSS/InvalidationSet.h>
|
|
#include <LibWeb/Forward.h>
|
|
|
|
namespace Web::DOM {
|
|
|
|
class StyleInvalidator : public GC::Cell {
|
|
GC_CELL(StyleInvalidator, GC::Cell);
|
|
GC_DECLARE_ALLOCATOR(StyleInvalidator);
|
|
|
|
public:
|
|
void invalidate(Node& node);
|
|
void add_pending_invalidation(GC::Ref<Node>, CSS::InvalidationSet&&, bool invalidate_elements_that_use_css_custom_properties);
|
|
bool has_pending_invalidations() const { return !m_pending_invalidations.is_empty(); }
|
|
|
|
virtual void visit_edges(Cell::Visitor& visitor) override;
|
|
|
|
private:
|
|
void perform_pending_style_invalidations(Node& node, bool invalidate_entire_subtree);
|
|
|
|
struct PendingInvalidation {
|
|
bool invalidate_elements_that_use_css_custom_properties { false };
|
|
CSS::InvalidationSet invalidation_set;
|
|
};
|
|
HashMap<GC::Ref<Node>, PendingInvalidation> m_pending_invalidations;
|
|
|
|
Vector<CSS::InvalidationSet> m_subtree_invalidation_sets;
|
|
bool m_invalidate_elements_that_use_css_custom_properties { false };
|
|
};
|
|
|
|
}
|