1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:37:46 +00:00

LibWeb: Make StackingContext sorting a lot faster

Stacking contexts are sorted after building a tree of them. They are
sorted by z-index first, DOM tree order second.

Sorting was previously *very* slow on pages with many stacking contexts.
That was because the sort() function used Node::is_before() in the
quick_sort comparator to see if one StackingContext was before another.
is_before() does tree traversal and can take quite a long time per call.

This patch avoids all that by letting StackingContext know its index
among all StackingContexts within the same document in tree order.
There's a noticeable snappiness increase on the CSS-FLEXBOX-1 spec page,
for instance. :^)
This commit is contained in:
Andreas Kling 2023-06-02 12:01:14 +02:00
parent 500b7b08d6
commit d6c3cbd958
3 changed files with 8 additions and 5 deletions

View file

@ -15,7 +15,7 @@ namespace Web::Painting {
class StackingContext {
public:
StackingContext(Layout::Box&, StackingContext* parent);
StackingContext(Layout::Box&, StackingContext* parent, size_t index_in_tree_order);
StackingContext* parent() { return m_parent; }
StackingContext const* parent() const { return m_parent; }
@ -47,6 +47,7 @@ private:
Gfx::FloatPoint m_transform_origin;
StackingContext* const m_parent { nullptr };
Vector<StackingContext*> m_children;
size_t m_index_in_tree_order { 0 };
void paint_internal(PaintContext&) const;
Gfx::FloatMatrix4x4 get_transformation_matrix(CSS::Transformation const& transformation) const;