LibWeb: Turn Element.scroll(0, 0) into a no-op when possible

For unscrolled elements (already at 0, 0) that aren't eligible to be the
Document.scrollingElement, we can short-circuit here and avoid doing a
synchronous relayout of the page.

This avoids a bunch of synchronous layouts on Speedometer3's NewsSite
subtests.
This commit is contained in:
Andreas Kling 2025-04-21 01:12:12 +02:00 committed by Andreas Kling
parent c394344e7d
commit 1242b9152e
Notes: github-actions[bot] 2025-04-22 10:10:56 +00:00

View file

@ -2813,6 +2813,16 @@ void Element::scroll(double x, double y)
if (document.document_element() == this && document.in_quirks_mode())
return;
// OPTIMIZATION: Scrolling an unscrolled element to (0, 0) is a no-op as long
// as the element is not eligible to be the Document.scrollingElement.
if (x == 0
&& y == 0
&& scroll_offset(ScrollOffsetFor::Self).is_zero()
&& this != document.body()
&& this != document.document_element()) {
return;
}
// NOTE: Ensure that layout is up-to-date before looking at metrics.
document.update_layout(UpdateLayoutReason::ElementScroll);