From c27ab92d1d2d28b25a746f0fa9844bb07d577db3 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Sun, 24 Sep 2023 11:24:39 +0200 Subject: [PATCH] feat: New torin benchmark for invalidations in the middle of the tree --- crates/torin/benches/bench.rs | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/crates/torin/benches/bench.rs b/crates/torin/benches/bench.rs index ccc15fe33..0ab83e44c 100644 --- a/crates/torin/benches/bench.rs +++ b/crates/torin/benches/bench.rs @@ -285,6 +285,82 @@ fn criterion_benchmark(c: &mut Criterion) { }) }, ); + + g.bench_function( + "big trees (deep + cached) + invalidated node in the middle", + |b| { + let mut layout = Torin::::new(); + let mut measurer = Some(TestingMeasurer); + let mut mocked_dom = TestingDOM::default(); + + let children_ids = (1..=101).into_iter().collect::>(); + + let mut root = 0; + + mocked_dom.add( + 0, + None, + children_ids.clone(), + Node::from_size_and_direction( + Size::Percentage(Length::new(100.0)), + Size::Percentage(Length::new(100.0)), + DirectionMode::Vertical, + ), + ); + + let levels = 20; + + for level in 0..levels { + for i in &children_ids { + let id = (level * 1000) + *i; + + mocked_dom.add( + id, + Some(root), + vec![], + Node::from_size_and_direction( + Size::Pixels(Length::new(100.0)), + Size::Pixels(Length::new(100.0)), + DirectionMode::Vertical, + ), + ); + + if *i == 101 { + root = id + } + } + } + + layout.find_best_root(&mut mocked_dom); + layout.measure( + 0, + Rect::new(Point2D::new(0.0, 0.0), Size2D::new(1000.0, 1000.0)), + &mut measurer, + &mut mocked_dom, + ); + + b.iter(|| { + black_box({ + mocked_dom.set_node( + 1, + Node::from_size_and_direction( + Size::Inner, + Size::Pixels(Length::new(10.0)), + DirectionMode::Vertical, + ), + ); + layout.invalidate(1000); + layout.find_best_root(&mut mocked_dom); + layout.measure( + 0, + Rect::new(Point2D::new(0.0, 0.0), Size2D::new(1000.0, 1000.0)), + &mut measurer, + &mut mocked_dom, + ) + }); + }) + }, + ); } criterion_group!(benches, criterion_benchmark);