feat: resume layout calls in VM instruction slices and expose slice statistics
Verify Tessera GUI / verify (push) Failing after 8m59s

This commit is contained in:
2026-10-23 01:00:49 +08:00
parent 33f94da927
commit 09c3902d84
8 changed files with 62 additions and 10 deletions
+3
View File
@@ -497,3 +497,6 @@ Flex main-axis policy: flexBasis is "auto" by default (zero basis when flex > 0,
When an occurrence's cross-axis constraint changes during settling, its preferred main-axis size is invalidated and remeasured. Any obsolete native flex allocation on that axis is removed for the replacement measurement, so narrowing a nested Column can increase wrapped text height. Source arrange allocations remain explicit. Preferred-size presence and values participate in convergence/cycle detection.
The source layout driver now uses Aster's resumable read-only call API with a soft quantum of 256 instructions. Pauses retain the same VM frames, operand/local roots, return contracts and read tracking; total instruction/frame limits still apply across slices. ui.stats().layoutSlices counts slices in the most recent solve (native fast path: 1). The worker currently resumes Pending immediately after yielding its OS time slice. Parking the solve across worker turns, scheduling other work and handling newer inputs before completion are not implemented yet. Native callbacks are not preempted. Only the completed settled frame is published.
+3
View File
@@ -149,3 +149,6 @@ Flex main-axis policy: flexBasis is "auto" by default (zero basis when flex > 0,
When an occurrence's cross-axis constraint changes during settling, its preferred main-axis size is invalidated and remeasured. Any obsolete native flex allocation on that axis is removed for the replacement measurement, so narrowing a nested Column can increase wrapped text height. Source arrange allocations remain explicit. Preferred-size presence and values participate in convergence/cycle detection.
The source layout driver now uses Aster's resumable read-only call API with a soft quantum of 256 instructions. Pauses retain the same VM frames, operand/local roots, return contracts and read tracking; total instruction/frame limits still apply across slices. ui.stats().layoutSlices counts slices in the most recent solve (native fast path: 1). The worker currently resumes Pending immediately after yielding its OS time slice. Parking the solve across worker turns, scheduling other work and handling newer inputs before completion are not implemented yet. Native callbacks are not preempted. Only the completed settled frame is published.
+3
View File
@@ -1127,6 +1127,9 @@ Flex main-axis policy: flexBasis is "auto" by default (zero basis when flex > 0,
When an occurrence's cross-axis constraint changes during settling, its preferred main-axis size is invalidated and remeasured. Any obsolete native flex allocation on that axis is removed for the replacement measurement, so narrowing a nested Column can increase wrapped text height. Source arrange allocations remain explicit. Preferred-size presence and values participate in convergence/cycle detection.
The source layout driver now uses Aster's resumable read-only call API with a soft quantum of 256 instructions. Pauses retain the same VM frames, operand/local roots, return contracts and read tracking; total instruction/frame limits still apply across slices. ui.stats().layoutSlices counts slices in the most recent solve (native fast path: 1). The worker currently resumes Pending immediately after yielding its OS time slice. Parking the solve across worker turns, scheduling other work and handling newer inputs before completion are not implemented yet. Native callbacks are not preempted. Only the completed settled frame is published.
## UI host object
Positional arguments only:
+21
View File
@@ -3889,6 +3889,27 @@ page.render(block)
);
}
#[test]
fn layout_slices_preserve_all_shared_occurrences() {
let children = std::iter::repeat_n("item", 40)
.collect::<Vec<_>>()
.join(", ");
let source = format!(
"class Wide: Row {{\n function measure(self: Wide, mount: Mount, constraints: Constraints): MeasureResult {{ return MeasureResult(340, 60) }}\n}}\nitem = RectBlock(2, 20)\npage = Page()\npage.render(Wide(0, 0, {children}))"
);
let (mut session, initial) = ReplSession::load(&source, "app.main", 269, 1).unwrap();
initial.validate().unwrap();
assert!(initial.frame.mounts.len() >= 41);
assert!(source_measure_stat(&mut session, "layoutSlices") > 1);
assert_eq!(
session
.execute("item.mounts().at(39).bounds().x", "app.main")
.unwrap()
.value,
"78"
);
}
#[test]
fn nested_flex_refreshes_natural_height_when_cross_width_changes() {
let (mut session, initial) = ReplSession::load(
+2
View File
@@ -88,6 +88,7 @@ pub struct LayoutRuntime {
pub measured: usize,
pub arranged: usize,
pub settle_passes: usize,
pub slices: usize,
pub viewport: Option<Size>,
}
@@ -492,6 +493,7 @@ impl LayoutRuntime {
self.measured = 0;
self.arranged = 0;
self.settle_passes = usize::from(!structural);
self.slices = usize::from(!structural);
let mut items = Vec::<Item<'_>>::new();
let mut work = vec![(root, None::<usize>, 0, root_constraints(self.viewport))];
let mut used = HashSet::new();
+28 -9
View File
@@ -795,20 +795,39 @@ pub fn render(
},
vec![desktop],
))?;
let result = vm.call_read_only_with_limits(
prepare,
&[],
endor_core::ExecutionLimits {
max_frames: 128,
max_instructions: 1_000_000,
},
);
let mut slices = 1;
let result = (|| {
let mut progress = vm.start_read_only_call(
prepare,
&[],
endor_core::ExecutionLimits {
max_frames: 128,
max_instructions: 1_000_000,
},
256,
)?;
loop {
match progress {
endor_core::ExecutionProgress::Complete { value, reads, .. } => {
return Ok((value, reads));
}
endor_core::ExecutionProgress::Pending { .. } => {
// The VM owns the continuation and keeps its read-only
// dependency scope intact. Worker-level parking follows.
std::thread::yield_now();
slices += 1;
progress = vm.resume_read_only_call(256)?;
}
}
}
})();
vm.release(prepare)?;
let (value, reads) = result.map_err(|error| crate::endor_host::runtime_error(vm, error))?;
vm.release_value(value)?;
let plan = plan
let mut plan = plan
.lock()
.map_err(|_| anyhow::anyhow!("layout plan poisoned"))?;
plan.runtime.slices = slices;
frame.commands.clear();
for (index, mount) in frame.mounts.iter_mut().enumerate() {
let [x, y, width, height] =
+1
View File
@@ -1152,6 +1152,7 @@ impl NativeCallable for Function {
("sourceMeasureMisses", session.measure_cache.misses as i64),
("arranged", session.layout.arranged as i64),
("layoutPasses", session.layout.settle_passes as i64),
("layoutSlices", session.layout.slices as i64),
] {
cx.set_attr(stats, name, Value::Number(value.into()))?;
}
+1 -1