layout: LAYOUT_STACK by measurement; depth test near the bound

This commit is contained in:
Meta Vens 2026-11-28 05:04:18 +01:00
commit 97e4099ece
2 changed files with 25 additions and 15 deletions

View file

@ -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 {

View file

@ -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