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
@@ -17,6 +17,12 @@ class ResizeObserverSize : public Bindings::PlatformObject {
|
||||
GC_DECLARE_ALLOCATOR(ResizeObserverSize);
|
||||
|
||||
public:
|
||||
struct RawSize {
|
||||
double inline_size { 0 };
|
||||
double block_size { 0 };
|
||||
};
|
||||
|
||||
static RawSize compute_box_size(DOM::Element& target, Bindings::ResizeObserverBoxOptions observed_box);
|
||||
static GC::Ref<ResizeObserverSize> calculate_box_size(JS::Realm& realm, DOM::Element& target, Bindings::ResizeObserverBoxOptions observed_box);
|
||||
|
||||
double inline_size() const { return m_inline_size; }
|
||||
@@ -25,6 +31,7 @@ public:
|
||||
double block_size() const { return m_block_size; }
|
||||
void set_block_size(double block_size) { m_block_size = block_size; }
|
||||
|
||||
bool equals(RawSize const& other) const;
|
||||
bool equals(ResizeObserverSize const& other) const;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user