From 97e4099ecec06de1c1db438a0248eb2e11c95d6c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 28 Nov 2026 05:04:18 +0100 Subject: [PATCH] layout: LAYOUT_STACK by measurement; depth test near the bound --- crates/thing-core/src/layout/mod.rs | 8 ++++---- crates/thing-core/tests/layout.rs | 32 +++++++++++++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/crates/thing-core/src/layout/mod.rs b/crates/thing-core/src/layout/mod.rs index 4d70adc..d686d7b 100644 --- a/crates/thing-core/src/layout/mod.rs +++ b/crates/thing-core/src/layout/mod.rs @@ -19,10 +19,10 @@ pub use measure::{Avail, Constraint, Leaf, Measure}; use crate::bind::BoundTree; use crate::diagnostic::Diagnostic; -/// The stack Taffy's recursion runs on, sized for a tree as deep as `Limits::max_tree_depth`: -/// twice the per-level use measured in a debug build, times the 256 levels and 8 for the entry, -/// rounded up to MiB. -const LAYOUT_STACK: usize = 64 * 1024 * 1024; +/// The stack Taffy's recursion runs on, sized for a tree as deep as `Limits::max_tree_depth`. +/// Measured in a debug build (`stack_per_level` in tests/layout.rs): 8992 bytes per level of Box +/// nesting. Twice that, times 256 levels and 8 for the entry, is 4.75 MB: 5 MiB. +const LAYOUT_STACK: usize = 5 * 1024 * 1024; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Metrics { diff --git a/crates/thing-core/tests/layout.rs b/crates/thing-core/tests/layout.rs index d8882a6..a09e366 100644 --- a/crates/thing-core/tests/layout.rs +++ b/crates/thing-core/tests/layout.rs @@ -552,17 +552,27 @@ fn depth() { }); assert!(laid.nodes.len() > 20); - // And so is a tree near the resolver's depth bound. - let tree = bind(&mut MemState::new(), &surface_of(chain(250))).unwrap(); - let laid = std::thread::scope(|scope| { - std::thread::Builder::new() - .stack_size(256 * 1024) - .spawn_scoped(scope, || layout(&tree, &pixels(800.0, 600.0, 1.0), &mut FixedMeasure::pixels(&[]))) - .unwrap() - .join() - .expect("layout stays inside 256 KiB") - }); - assert_eq!(laid.nodes.len(), 251); + // And so is a tree near the resolver's depth bound. The tree is built and dropped on a + // roomy thread: only layout is held to 256 KiB. + let nodes = std::thread::Builder::new() + .stack_size(64 * 1024 * 1024) + .spawn(|| { + let tree = bind(&mut MemState::new(), &surface_of(chain(250))).unwrap(); + std::thread::scope(|scope| { + std::thread::Builder::new() + .stack_size(256 * 1024) + .spawn_scoped(scope, || layout(&tree, &pixels(800.0, 600.0, 1.0), &mut FixedMeasure::pixels(&[]))) + .unwrap() + .join() + .expect("layout stays inside 256 KiB") + .nodes + .len() + }) + }) + .unwrap() + .join() + .unwrap(); + assert_eq!(nodes, 251); } /// How much stack one level of Box nesting takes. Run with `--nocapture` in a debug build to set