mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-18 00:09:44 +00:00
LibWeb: Don't allocate a new HeapFunction 60 times per second
We can reuse the same HeapFunction when queueing up a rendering task on the HTML event loop. No need to create extra work for the garbage collector like this.
This commit is contained in:
parent
1b127ac082
commit
5c6b879715
Notes:
github-actions[bot]
2024-10-25 08:22:14 +00:00
Author: https://github.com/awesomekling
Commit: 5c6b879715
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1956
Reviewed-by: https://github.com/gmta ✅
2 changed files with 146 additions and 134 deletions
|
@ -32,6 +32,10 @@ EventLoop::EventLoop(Type type)
|
||||||
{
|
{
|
||||||
m_task_queue = heap().allocate_without_realm<TaskQueue>(*this);
|
m_task_queue = heap().allocate_without_realm<TaskQueue>(*this);
|
||||||
m_microtask_queue = heap().allocate_without_realm<TaskQueue>(*this);
|
m_microtask_queue = heap().allocate_without_realm<TaskQueue>(*this);
|
||||||
|
|
||||||
|
m_rendering_task_function = JS::create_heap_function(heap(), [this] {
|
||||||
|
update_the_rendering();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
EventLoop::~EventLoop() = default;
|
EventLoop::~EventLoop() = default;
|
||||||
|
@ -43,6 +47,7 @@ void EventLoop::visit_edges(Visitor& visitor)
|
||||||
visitor.visit(m_microtask_queue);
|
visitor.visit(m_microtask_queue);
|
||||||
visitor.visit(m_currently_running_task);
|
visitor.visit(m_currently_running_task);
|
||||||
visitor.visit(m_backup_incumbent_settings_object_stack);
|
visitor.visit(m_backup_incumbent_settings_object_stack);
|
||||||
|
visitor.visit(m_rendering_task_function);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventLoop::schedule()
|
void EventLoop::schedule()
|
||||||
|
@ -239,7 +244,12 @@ void EventLoop::queue_task_to_update_the_rendering()
|
||||||
if (document->is_decoded_svg())
|
if (document->is_decoded_svg())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
queue_global_task(Task::Source::Rendering, *navigable->active_window(), JS::create_heap_function(navigable->heap(), [this] mutable {
|
queue_global_task(Task::Source::Rendering, *navigable->active_window(), *m_rendering_task_function);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EventLoop::update_the_rendering()
|
||||||
|
{
|
||||||
VERIFY(!m_is_running_rendering_task);
|
VERIFY(!m_is_running_rendering_task);
|
||||||
m_is_running_rendering_task = true;
|
m_is_running_rendering_task = true;
|
||||||
ScopeGuard const guard = [this] {
|
ScopeGuard const guard = [this] {
|
||||||
|
@ -390,8 +400,6 @@ void EventLoop::queue_task_to_update_the_rendering()
|
||||||
document->fonts()->resolve_ready_promise();
|
document->fonts()->resolve_ready_promise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-task
|
// https://html.spec.whatwg.org/multipage/webappapis.html#queue-a-task
|
||||||
|
|
|
@ -81,6 +81,8 @@ private:
|
||||||
|
|
||||||
virtual void visit_edges(Visitor&) override;
|
virtual void visit_edges(Visitor&) override;
|
||||||
|
|
||||||
|
void update_the_rendering();
|
||||||
|
|
||||||
Type m_type { Type::Window };
|
Type m_type { Type::Window };
|
||||||
|
|
||||||
JS::GCPtr<TaskQueue> m_task_queue;
|
JS::GCPtr<TaskQueue> m_task_queue;
|
||||||
|
@ -116,6 +118,8 @@ private:
|
||||||
bool m_skip_event_loop_processing_steps { false };
|
bool m_skip_event_loop_processing_steps { false };
|
||||||
|
|
||||||
bool m_is_running_rendering_task { false };
|
bool m_is_running_rendering_task { false };
|
||||||
|
|
||||||
|
JS::GCPtr<JS::HeapFunction<void()>> m_rendering_task_function;
|
||||||
};
|
};
|
||||||
|
|
||||||
EventLoop& main_thread_event_loop();
|
EventLoop& main_thread_event_loop();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue