mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-24 05:25:13 +00:00
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:
parent
c394344e7d
commit
1242b9152e
Notes:
github-actions[bot]
2025-04-22 10:10:56 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/1242b9152e1 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4424 Reviewed-by: https://github.com/gmta
1 changed files with 10 additions and 0 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue