From 46097c6753f6d147786abf9b8d59d5535d3a5bf5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 8 Jul 2025 04:18:46 +0200 Subject: [PATCH] LibWeb: Avoid unnecessary save/restore in `paint_background()` `paint_background()` is invoked for each PaintableBox, so by avoiding save/restore pair emitted for each call, we substantially decrease display list size. Website | DisplayList Items Before | DisplayList Items After -------------|--------------------------|------------------------- ladybird.org | 2753 | 1431 null.com | 5298 | 4714 discord.com | 6598 | 5360 --- Libraries/LibWeb/Painting/BackgroundPainting.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Libraries/LibWeb/Painting/BackgroundPainting.cpp b/Libraries/LibWeb/Painting/BackgroundPainting.cpp index 62833c01ec6..6263edbc90d 100644 --- a/Libraries/LibWeb/Painting/BackgroundPainting.cpp +++ b/Libraries/LibWeb/Painting/BackgroundPainting.cpp @@ -90,9 +90,11 @@ void paint_background(PaintContext& context, PaintableBox const& paintable_box, display_list_recorder.save_layer(); } - DisplayListRecorderStateSaver state { display_list_recorder }; bool is_root_element = paintable_box.layout_node().is_root_element(); - if (resolved_background.needs_text_clip && !is_root_element) { + bool needs_text_clip = resolved_background.needs_text_clip && !is_root_element; + + if (needs_text_clip) { + display_list_recorder.save(); auto display_list = compute_text_clip_paths(context, paintable_box, resolved_background.background_rect.location()); auto rect = context.rounded_device_rect(resolved_background.background_rect); display_list_recorder.add_mask(move(display_list), rect.to_type()); @@ -335,6 +337,9 @@ void paint_background(PaintContext& context, PaintableBox const& paintable_box, } } + if (needs_text_clip) { + display_list_recorder.restore(); + } if (paint_into_isolated_group) { display_list_recorder.restore(); }