From 9840a8c75087a8ba9ad40f6fb07dc777746195f1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 22 Apr 2025 00:42:41 +0200 Subject: [PATCH] LibWeb: Turn Window.scroll(0, 0) into a no-op when possible For unscrolled viewports (already at 0, 0), 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 (Nuxt version) subtests. --- Libraries/LibWeb/HTML/Window.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Libraries/LibWeb/HTML/Window.cpp b/Libraries/LibWeb/HTML/Window.cpp index 3baff34016a..55aa9a55b29 100644 --- a/Libraries/LibWeb/HTML/Window.cpp +++ b/Libraries/LibWeb/HTML/Window.cpp @@ -1465,6 +1465,10 @@ void Window::scroll(ScrollToOptions const& options) x = HTML::normalize_non_finite_values(x); y = HTML::normalize_non_finite_values(y); + // OPTIMIZATION: If we're asked to scroll to (0, 0) and we're already there, do nothing. + if (x == 0 && y == 0 && navigable->viewport_scroll_offset().is_zero()) + return; + // 5. Let viewport width be the width of the viewport excluding the width of the scroll bar, if any. auto viewport_width = viewport_rect.width();