mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
LibWeb: Avoid allocating DOMRect objects for internal engine use
Instead of bothering the GC heap with a bunch of DOMRect allocations, we can just pass around CSSPixelRect internally in many cases. Before this change, we were generating so much DOMRect garbage that we had to do a garbage collection *every frame* on the Immich demo. This was due to the large number of intersection observers checked. We still need to relax way more when idle, but for comparison, before this change, when doing nothing for 10 seconds on Immich, we'd spend 2.5 seconds updating intersection observers. After this change, we now spend 600 ms.
This commit is contained in:
committed by
Andreas Kling
parent
bf517f9ac2
commit
f0abf5a43b
Notes:
github-actions[bot]
2025-03-22 19:34:58 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/f0abf5a43b3 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4049 Reviewed-by: https://github.com/gmta
@@ -3090,7 +3090,7 @@ void WebDriverConnection::delete_cookies(Optional<StringView> const& name)
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webdriver/#dfn-calculate-the-absolute-position
|
||||
Gfx::IntPoint WebDriverConnection::calculate_absolute_position_of_element(GC::Ref<Web::Geometry::DOMRect> rect)
|
||||
Gfx::IntPoint WebDriverConnection::calculate_absolute_position_of_element(Web::CSSPixelRect rect)
|
||||
{
|
||||
// 1. Let rect be the value returned by calling getBoundingClientRect().
|
||||
|
||||
@@ -3098,10 +3098,10 @@ Gfx::IntPoint WebDriverConnection::calculate_absolute_position_of_element(GC::Re
|
||||
auto const* window = current_top_level_browsing_context()->active_window();
|
||||
|
||||
// 3. Let x be (scrollX of window + rect’s x coordinate).
|
||||
auto x = (window ? static_cast<int>(window->scroll_x()) : 0) + static_cast<int>(rect->x());
|
||||
auto x = (window ? static_cast<int>(window->scroll_x()) : 0) + static_cast<int>(rect.x());
|
||||
|
||||
// 4. Let y be (scrollY of window + rect’s y coordinate).
|
||||
auto y = (window ? static_cast<int>(window->scroll_y()) : 0) + static_cast<int>(rect->y());
|
||||
auto y = (window ? static_cast<int>(window->scroll_y()) : 0) + static_cast<int>(rect.y());
|
||||
|
||||
// 5. Return a pair of (x, y).
|
||||
return { x, y };
|
||||
@@ -3115,8 +3115,8 @@ Gfx::IntRect WebDriverConnection::calculate_absolute_rect_of_element(Web::DOM::E
|
||||
return {
|
||||
coordinates.x(),
|
||||
coordinates.y(),
|
||||
static_cast<int>(bounding_rect->width()),
|
||||
static_cast<int>(bounding_rect->height())
|
||||
static_cast<int>(bounding_rect.width()),
|
||||
static_cast<int>(bounding_rect.height())
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user