mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-25 10:48:41 +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:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user