LibWeb: Re-evaluate media queries only when things they depend on change

Before this change we were re-evaluating media queries on every frame
which adds up in 1-4% in profiles on Discord.
This commit is contained in:
Aliaksandr Kalenik 2025-08-05 16:56:05 +02:00 committed by Jelle Raaijmakers
parent 3920194bca
commit 7a34bc2700
Notes: github-actions[bot] 2025-08-05 15:26:02 +00:00
4 changed files with 17 additions and 3 deletions

View file

@ -3412,12 +3412,17 @@ void Document::run_the_scroll_steps()
void Document::add_media_query_list(GC::Ref<CSS::MediaQueryList> media_query_list)
{
m_needs_media_query_evaluation = true;
m_media_query_lists.append(*media_query_list);
}
// https://drafts.csswg.org/cssom-view/#evaluate-media-queries-and-report-changes
void Document::evaluate_media_queries_and_report_changes()
{
if (!m_needs_media_query_evaluation)
return;
m_needs_media_query_evaluation = false;
// NOTE: Not in the spec, but we take this opportunity to prune null WeakPtrs.
m_media_query_lists.remove_all_matching([](auto& it) {
return it.is_null();