mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
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:
committed by
Alexander Kalenik
parent
935f76f88e
commit
5fdcf207f8
Notes:
github-actions[bot]
2026-02-21 02:52:27 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/5fdcf207f84 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8051
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user