From ead742886b9e1efb7496de9369aef2231183a861 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 16 Mar 2024 14:47:57 +0100 Subject: [PATCH] LibWeb: Don't run HTMLImageElement timer when there is no animation Before this change, we would wake up on every event loop iteration to drive animations in single-frame images. This was a complete waste of time and caused 100% CPU usage on our main GitHub repo page. With this change, CPU usage is ~1% when idle on the same page. :^) --- Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp index ac1215e92c9804..2b2723de317ae4 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -838,7 +838,13 @@ void HTMLImageElement::handle_failed_fetch() void HTMLImageElement::restart_the_animation() { m_current_frame_index = 0; - m_animation_timer->start(); + + auto image_data = m_current_request->image_data(); + if (image_data && image_data->frame_count() > 1) { + m_animation_timer->start(); + } else { + m_animation_timer->stop(); + } } // https://html.spec.whatwg.org/multipage/images.html#update-the-source-set