From 6022f070ebd03776d45d6a9d9df559b44067838d Mon Sep 17 00:00:00 2001 From: Elena Torro Date: Wed, 10 Jun 2026 13:22:32 +0200 Subject: [PATCH] :zap: cache shape depth in reflow sort --- render-wasm/src/shapes/modifiers.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/render-wasm/src/shapes/modifiers.rs b/render-wasm/src/shapes/modifiers.rs index 109fc605b2..3da9bd73fb 100644 --- a/render-wasm/src/shapes/modifiers.rs +++ b/render-wasm/src/shapes/modifiers.rs @@ -482,11 +482,8 @@ pub fn propagate_modifiers( // are already reflowed before their parents. let mut layout_reflows_vec: Vec = std::mem::take(&mut layout_reflows).into_iter().collect(); - layout_reflows_vec.sort_unstable_by(|id_a, id_b| { - let da = shapes.get_depth(id_a); - let db = shapes.get_depth(id_b); - db.cmp(&da) - }); + // Deepest-first; cache get_depth (O(depth) parent walk) per id. + layout_reflows_vec.sort_by_cached_key(|id| std::cmp::Reverse(shapes.get_depth(id))); // This temporary bounds is necesary so the layouts can be calculated // correctly but will be discarded before the next iteration for the