LibWeb: Skip queuing a rendering task if task queue already contains it
Some checks are pending
CI / Lagom (false, FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, macos-14, macOS, Clang) (push) Waiting to run
CI / Lagom (false, NO_FUZZ, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (true, NO_FUZZ, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Push notes / build (push) Waiting to run

If, by the time we need to schedule rendering of the next frame, the
previous one is still not processed, we could skip it instead of growing
task queue.

Should help with https://github.com/LadybirdBrowser/ladybird/issues/1647
This commit is contained in:
Aliaksandr Kalenik 2024-10-06 15:16:35 +02:00 committed by Alexander Kalenik
parent ea971792b5
commit 908455ab06
Notes: github-actions[bot] 2024-10-06 14:26:28 +00:00
3 changed files with 15 additions and 0 deletions

View file

@ -221,6 +221,11 @@ void EventLoop::queue_task_to_update_the_rendering()
// 2. Set eventLoop's last render opportunity time to the unsafe shared current time.
m_last_render_opportunity_time = HighResolutionTime::unsafe_shared_current_time();
// OPTIMIZATION: If there are already rendering tasks in the queue, we don't need to queue another one.
if (m_task_queue->has_rendering_tasks()) {
return;
}
// 3. For each navigable that has a rendering opportunity, queue a global task on the rendering task source given navigable's active window to update the rendering:
for (auto& navigable : all_navigables()) {
if (!navigable->is_traversable())

View file

@ -88,4 +88,13 @@ Task const* TaskQueue::last_added_task() const
return m_tasks.last();
}
bool TaskQueue::has_rendering_tasks() const
{
for (auto const& task : m_tasks) {
if (task->source() == Task::Source::Rendering)
return true;
}
return false;
}
}

View file

@ -23,6 +23,7 @@ public:
bool is_empty() const { return m_tasks.is_empty(); }
bool has_runnable_tasks() const;
bool has_rendering_tasks() const;
void add(JS::NonnullGCPtr<HTML::Task>);
JS::GCPtr<HTML::Task> take_first_runnable();