mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-29 15:58:47 +00:00
LibWeb: Limit sibling style invalidation by max distance
If an element is affected only by selectors using the direct sibling combinator `+`, we can calculate the maximum invalidation distance and use it to limit style invalidation. For example, the selector `.a + .b + .c` has a maximum invalidation distance of 2, meaning we can skip invalidating any element affected by this selector if it's more than two siblings away from the element that triggered the style invalidation. This change results in visible performance improvement when hovering PR list on GitHub.
This commit is contained in:
parent
46abdd1126
commit
84ecaaa75c
Notes:
github-actions[bot]
2025-03-10 17:57:49 +00:00
Author: https://github.com/kalenikaliaksandr
Commit: 84ecaaa75c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3891
6 changed files with 61 additions and 10 deletions
|
@ -460,16 +460,21 @@ void Node::invalidate_style(StyleInvalidationReason reason)
|
|||
}
|
||||
}
|
||||
|
||||
size_t current_sibling_distance = 1;
|
||||
for (auto* sibling = next_sibling(); sibling; sibling = sibling->next_sibling()) {
|
||||
if (auto* element = as_if<Element>(sibling)) {
|
||||
bool needs_to_invalidate = false;
|
||||
if (reason == StyleInvalidationReason::NodeInsertBefore || reason == StyleInvalidationReason::NodeRemove) {
|
||||
needs_to_invalidate = element->style_affected_by_structural_changes();
|
||||
} else {
|
||||
needs_to_invalidate = element->affected_by_sibling_combinator() || element->affected_by_nth_child_pseudo_class();
|
||||
} else if (element->affected_by_indirect_sibling_combinator() || element->affected_by_nth_child_pseudo_class()) {
|
||||
needs_to_invalidate = true;
|
||||
} else if (element->affected_by_direct_sibling_combinator() && current_sibling_distance <= element->sibling_invalidation_distance()) {
|
||||
needs_to_invalidate = true;
|
||||
}
|
||||
if (needs_to_invalidate)
|
||||
if (needs_to_invalidate) {
|
||||
element->set_entire_subtree_needs_style_update(true);
|
||||
}
|
||||
current_sibling_distance++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue