1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:07:34 +00:00

LibWeb: Cache flex item main sizes to avoid relayout during same cycle

This makes twitter.com actually load & render (although not very well.)
This commit is contained in:
Andreas Kling 2022-07-06 00:21:37 +02:00
parent 8733fbae76
commit d2b7d2440f
2 changed files with 12 additions and 1 deletions

View file

@ -619,7 +619,16 @@ void FlexFormattingContext::determine_flex_base_size_and_hypothetical_main_size(
if (has_definite_main_size(child_box))
return specified_main_size_of_child_box(child_box);
return calculate_indefinite_main_size(flex_item);
// NOTE: To avoid repeated layout work, we keep a cache of flex item main sizes on the
// root FormattingState object. It's available through a full layout cycle.
// FIXME: Make sure this cache isn't overly permissive..
auto& size_cache = m_state.m_root.flex_item_size_cache;
auto it = size_cache.find(&flex_item.box);
if (it != size_cache.end())
return it->value;
auto main_size = calculate_indefinite_main_size(flex_item);
size_cache.set(&flex_item.box, main_size);
return main_size;
}();
// The hypothetical main size is the items flex base size clamped according to its used min and max main sizes (and flooring the content box size at zero).