1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 09:34:59 +00:00

LibWeb: Put a cap on how many image loads we'll batch up before flushing

The BatchingDispatcher mechanism is used by HTMLImageElement to avoid
decoding one image at a time, since interleaving decode/layout/repaint
over and over takes way more time than doing many decodes followed by
a single layout/repaint pair.

Before this change, we didn't have a limit on how many batched loads
we'd allow ourselves to queue up, which could lead to situations where
more and more images kept being added to the queue, and never getting
processed.

This fixes the issue by putting an arbitrary limit (16) on the number
of batched image loads, and then allowing the flush to happen after
that instead of re-deferring processing.
This commit is contained in:
Andreas Kling 2023-12-28 10:24:00 +01:00
parent 473f3a0931
commit 6fe6166607

View file

@ -299,8 +299,13 @@ public:
void enqueue(JS::SafeFunction<void()> callback)
{
// NOTE: We don't want to flush the queue on every image load, since that would be slow.
// However, we don't want to keep growing the batch forever either.
static constexpr size_t max_loads_to_batch_before_flushing = 16;
m_queue.append(move(callback));
m_timer->restart();
if (m_queue.size() < max_loads_to_batch_before_flushing)
m_timer->restart();
}
private: