LibWeb: Avoid GC allocation in ResizeObservation::is_active()

Extract the box size computation into a new compute_box_size() that
returns a plain struct with two doubles, and use it in is_active()
instead of calculate_box_size() which allocates a GC-managed
ResizeObserverSize object.

Since is_active() only needs to compare sizes and immediately discards
the result, there's no reason to involve the GC. The GC-allocating
calculate_box_size() now delegates to compute_box_size() internally.

This was 2.6% of CPU time while playing a YouTube video.
This commit is contained in:
Andreas Kling
2026-02-21 01:33:41 +01:00
committed by Alexander Kalenik
parent 935f76f88e
commit 5fdcf207f8
Notes: github-actions[bot] 2026-02-21 02:52:27 +00:00
3 changed files with 32 additions and 19 deletions

View File

@@ -40,11 +40,11 @@ void ResizeObservation::visit_edges(JS::Cell::Visitor& visitor)
bool ResizeObservation::is_active()
{
// 1. Set currentSize by calculate box size given target and observedBox.
auto current_size = ResizeObserverSize::calculate_box_size(m_realm, m_target, m_observed_box);
auto current_size = ResizeObserverSize::compute_box_size(m_target, m_observed_box);
// 2. Return true if currentSize is not equal to the first entry in this.lastReportedSizes.
VERIFY(!m_last_reported_sizes.is_empty());
if (!m_last_reported_sizes.first()->equals(*current_size))
if (!m_last_reported_sizes.first()->equals(current_size))
return true;
// 3. Return false.