1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:57:44 +00:00

LibWeb: Optimize scroll offset and clip state recalculation

In this commit we have optimized the handling of scroll offsets and
clip rectangles to improve performance. Previously, the process
involved multiple full traversals of the paintable tree before each
repaint, which was highly inefficient, especially on pages with a
large number of paintables. The steps were:

1. Traverse the paintable tree to identify all boxes with scrollable or
   clipped overflow.
2. Gather the accumulated scroll offset or clip rectangle for each box.
3. Perform another traversal to apply the corresponding scroll offset
   and clip rectangle to each paintable.

To address this, we've adopted a new strategy that separates the
assignment of the scroll/clip frame from the refresh of accumulated
scroll offsets and clip rectangles, thus reducing the workload:

1. Post-relayout: Identify all boxes with overflow and link each
   paintable to the state of its containing scroll/clip frame.
2. Pre-repaint: Update the clip rectangle and scroll offset only in the
   previously identified boxes.

This adjustment ensures that the costly tree traversals are only
necessary after a relayout, substantially decreasing the amount of work
required before each repaint.
This commit is contained in:
Aliaksandr Kalenik 2024-02-08 17:30:07 +01:00 committed by Andreas Kling
parent fc40d35012
commit 76d1536307
8 changed files with 189 additions and 104 deletions

View file

@ -1064,6 +1064,11 @@ void Document::update_layout()
set_needs_to_resolve_paint_only_properties();
if (navigable()->is_traversable()) {
// NOTE: The assignment of scroll frames only needs to occur for traversables because they take care of all
// nested navigable documents.
paintable()->assign_scroll_frames();
paintable()->assign_clip_frames();
page().client().page_did_layout();
}