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:
Andreas Kling 2025-03-21 19:38:12 -05:00 committed by Andreas Kling
parent bf517f9ac2
commit f0abf5a43b
Notes: github-actions[bot] 2025-03-22 19:34:58 +00:00
12 changed files with 79 additions and 68 deletions

View file

@ -1180,11 +1180,9 @@ GC::Ref<Geometry::DOMRectList> Range::get_client_rects()
// areas returned by invoking getClientRects() on the element.
if (contains_node(*node) && !contains_node(*node->parent())) {
auto const& element = static_cast<DOM::Element const&>(*node);
GC::Ref<Geometry::DOMRectList> const element_rects = element.get_client_rects();
for (u32 i = 0; i < element_rects->length(); i++) {
auto rect = element_rects->item(i);
rects.append(Geometry::DOMRect::create(realm(),
Gfx::FloatRect(rect->x(), rect->y(), rect->width(), rect->height())));
auto const element_rects = element.get_client_rects();
for (auto& rect : element_rects) {
rects.append(MUST(Geometry::DOMRect::construct_impl(realm(), static_cast<double>(rect.x()), static_cast<double>(rect.y()), static_cast<double>(rect.width()), static_cast<double>(rect.height()))));
}
}
} else if (node_type == NodeType::TEXT_NODE) {