diff --git a/src/inspector.rs b/src/inspector.rs index b8687b2d..58dd8a83 100644 --- a/src/inspector.rs +++ b/src/inspector.rs @@ -77,6 +77,8 @@ pub struct Capture { pub post_layout: Instant, pub end: Instant, pub taffy_duration: Duration, + pub taffy_node_count: usize, + pub taffy_depth: usize, pub window: Option>, pub window_size: Size, pub scale: f64, @@ -305,13 +307,24 @@ fn stats(capture: &Capture) -> impl View { "Taffy time", format!("{:.4} ms", capture.taffy_duration.as_secs_f64() * 1000.0), ); + let taffy_node_count = info("Taffy node count", capture.taffy_node_count.to_string()); + let taffy_depth = info("Taffy depth", capture.taffy_depth.to_string()); let paint_time = info( "Paint time", format!("Paint time: {:.4} ms", paint_time.as_secs_f64() * 1000.0), ); let w = info("Window Width", format!("{}", capture.window_size.width)); let h = info("Window Height", format!("{}", capture.window_size.height)); - stack((layout_time, taffy_time, paint_time, w, h)).style(|s| s.flex_col()) + stack(( + layout_time, + taffy_time, + taffy_node_count, + taffy_depth, + paint_time, + w, + h, + )) + .style(|s| s.flex_col()) } fn selected_view(capture: &Rc, selected: RwSignal>) -> impl View { diff --git a/src/window_handle.rs b/src/window_handle.rs index 7fda7c9b..b24cad7f 100644 --- a/src/window_handle.rs +++ b/src/window_handle.rs @@ -549,8 +549,23 @@ impl WindowHandle { .values_mut() .for_each(|state| state.request_layout = true); + fn get_taffy_depth(taffy: &taffy::Taffy, root: taffy::node::Node) -> usize { + let children = taffy.children(root).unwrap(); + if children.is_empty() { + 1 + } else { + children + .iter() + .map(|child| get_taffy_depth(taffy, *child)) + .max() + .unwrap() + + 1 + } + } + let start = Instant::now(); + let taffy_root_node = self.app_state.view_state(self.view.id()).node; let taffy_duration = self.layout(); let post_layout = Instant::now(); let window = self.paint().map(Rc::new); @@ -562,6 +577,8 @@ impl WindowHandle { post_layout, end, taffy_duration, + taffy_node_count: self.app_state.taffy.total_node_count(), + taffy_depth: get_taffy_depth(&self.app_state.taffy, taffy_root_node), window, window_size: self.size.get_untracked() / self.app_state.scale, scale: self.scale * self.app_state.scale,