diff --git a/README.md b/README.md index 5c43c93..71fcd68 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/README.md b/src/README.md index 2505aa8..33096fa 100644 --- a/src/README.md +++ b/src/README.md @@ -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. diff --git a/src/api.rs b/src/api.rs index 974928a..1010b1c 100644 --- a/src/api.rs +++ b/src/api.rs @@ -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: diff --git a/src/endor_host.rs b/src/endor_host.rs index c2d67a6..46169d1 100644 --- a/src/endor_host.rs +++ b/src/endor_host.rs @@ -3889,6 +3889,27 @@ page.render(block) ); } + #[test] + fn layout_slices_preserve_all_shared_occurrences() { + let children = std::iter::repeat_n("item", 40) + .collect::>() + .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( diff --git a/src/layout.rs b/src/layout.rs index 3cefbe5..46b2273 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -88,6 +88,7 @@ pub struct LayoutRuntime { pub measured: usize, pub arranged: usize, pub settle_passes: usize, + pub slices: usize, pub viewport: Option, } @@ -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::>::new(); let mut work = vec![(root, None::, 0, root_constraints(self.viewport))]; let mut used = HashSet::new(); diff --git a/src/source_layout.rs b/src/source_layout.rs index 829d369..26b5d50 100644 --- a/src/source_layout.rs +++ b/src/source_layout.rs @@ -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] = diff --git a/src/ui_bridge.rs b/src/ui_bridge.rs index 010726a..7cdee29 100644 --- a/src/ui_bridge.rs +++ b/src/ui_bridge.rs @@ -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()))?; } diff --git a/vendor/aster b/vendor/aster index e511e39..1c729b4 160000 --- a/vendor/aster +++ b/vendor/aster @@ -1 +1 @@ -Subproject commit e511e393d98a5d87015dc8c42cfa59a82d48a422 +Subproject commit 1c729b412871c6c68c9afeb81550e1b6b3eaa3f5