Skip to content

Commit 3b4498b

Browse files
authored
Add taffy node count and depth to inspector (lapce#139)
1 parent 7094fb3 commit 3b4498b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/inspector.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ pub struct Capture {
7777
pub post_layout: Instant,
7878
pub end: Instant,
7979
pub taffy_duration: Duration,
80+
pub taffy_node_count: usize,
81+
pub taffy_depth: usize,
8082
pub window: Option<Rc<DynamicImage>>,
8183
pub window_size: Size,
8284
pub scale: f64,
@@ -305,13 +307,24 @@ fn stats(capture: &Capture) -> impl View {
305307
"Taffy time",
306308
format!("{:.4} ms", capture.taffy_duration.as_secs_f64() * 1000.0),
307309
);
310+
let taffy_node_count = info("Taffy node count", capture.taffy_node_count.to_string());
311+
let taffy_depth = info("Taffy depth", capture.taffy_depth.to_string());
308312
let paint_time = info(
309313
"Paint time",
310314
format!("Paint time: {:.4} ms", paint_time.as_secs_f64() * 1000.0),
311315
);
312316
let w = info("Window Width", format!("{}", capture.window_size.width));
313317
let h = info("Window Height", format!("{}", capture.window_size.height));
314-
stack((layout_time, taffy_time, paint_time, w, h)).style(|s| s.flex_col())
318+
stack((
319+
layout_time,
320+
taffy_time,
321+
taffy_node_count,
322+
taffy_depth,
323+
paint_time,
324+
w,
325+
h,
326+
))
327+
.style(|s| s.flex_col())
315328
}
316329

317330
fn selected_view(capture: &Rc<Capture>, selected: RwSignal<Option<Id>>) -> impl View {

src/window_handle.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,23 @@ impl WindowHandle {
549549
.values_mut()
550550
.for_each(|state| state.request_layout = true);
551551

552+
fn get_taffy_depth(taffy: &taffy::Taffy, root: taffy::node::Node) -> usize {
553+
let children = taffy.children(root).unwrap();
554+
if children.is_empty() {
555+
1
556+
} else {
557+
children
558+
.iter()
559+
.map(|child| get_taffy_depth(taffy, *child))
560+
.max()
561+
.unwrap()
562+
+ 1
563+
}
564+
}
565+
552566
let start = Instant::now();
553567

568+
let taffy_root_node = self.app_state.view_state(self.view.id()).node;
554569
let taffy_duration = self.layout();
555570
let post_layout = Instant::now();
556571
let window = self.paint().map(Rc::new);
@@ -562,6 +577,8 @@ impl WindowHandle {
562577
post_layout,
563578
end,
564579
taffy_duration,
580+
taffy_node_count: self.app_state.taffy.total_node_count(),
581+
taffy_depth: get_taffy_depth(&self.app_state.taffy, taffy_root_node),
565582
window,
566583
window_size: self.size.get_untracked() / self.app_state.scale,
567584
scale: self.scale * self.app_state.scale,

0 commit comments

Comments
 (0)