diff --git a/src/README.md b/src/README.md index 95cdc41..f46007c 100644 --- a/src/README.md +++ b/src/README.md @@ -203,3 +203,6 @@ Source paint now uses a resumable read-only VM call with the same 256-instructio Layout and paint drivers now prepare one occurrence at a time. Their fixed-size outer bytecode repeats on the same VM frame; a short-lived helper retains only the current call, its bounds/arguments and collector. The helper is released before the next occurrence. Layout keeps bottom-up measure, top-down arrange and the same settling loop. Paint advances even intrinsic method classification through VM quanta. The weak occurrence list and native scratch/output data remain proportional to the actual tree, but preparation no longer allocates managed callables/Bounds for the whole tree before the first slice. All helpers share the original read-only scope and cumulative instruction/frame limits. Weak-list copying, structural extraction, settling and final projection remain bounded atomic native work. + + +Presentation dependency diagnostics record a counter and the last invalidated object kind/identity and version transition. ui.stats exposes dependencyInvalidations and lastInvalidDependency without retaining the dependency or rendering its data. These help distinguish expected input invalidation from repeated background refresh. diff --git a/src/presentation.rs b/src/presentation.rs index b2b0f3c..d24f07c 100644 --- a/src/presentation.rs +++ b/src/presentation.rs @@ -22,6 +22,8 @@ pub(crate) struct Presentation { pub published_version: u64, pub force_frame: bool, pub paint_reads: std::collections::BTreeMap, + pub dependency_invalidations: usize, + pub last_invalid_dependency: String, pub layout_reads: std::collections::BTreeMap, pub measure_cache: crate::source_layout::Cache, pub snapshot_visited: usize, @@ -30,13 +32,27 @@ pub(crate) struct Presentation { impl Presentation { pub fn observe_changes(&mut self, vm: &Vm, changes: &ChangeBatch) { - if self - .paint_reads + if let Some((phase, object, version)) = self + .layout_reads .iter() - .chain(self.layout_reads.iter()) - .any(|(object, version)| vm.change_version(*object).ok() != Some(*version)) + .map(|(object, version)| ("layout", object, version)) + .chain( + self.paint_reads + .iter() + .map(|(object, version)| ("paint", object, version)), + ) + .find(|(_, object, version)| vm.change_version(**object).ok() != Some(**version)) { self.force_frame = true; + self.dependency_invalidations = self.dependency_invalidations.saturating_add(1); + let kind = vm + .object(*object) + .map(|value| value.payload().kind_name()) + .unwrap_or("released"); + self.last_invalid_dependency = format!( + "{phase} {kind} {object}: {version} -> {:?}", + vm.change_version(*object).ok() + ); } self.render_cache.invalidate(ChangeBatch { changes: changes.changes.clone(), @@ -91,6 +107,8 @@ impl Presentation { published_version: 0, force_frame: false, paint_reads: std::collections::BTreeMap::new(), + dependency_invalidations: 0, + last_invalid_dependency: String::new(), layout_reads: std::collections::BTreeMap::new(), measure_cache: crate::source_layout::Cache::default(), snapshot_visited: 0, diff --git a/src/ui_bridge.rs b/src/ui_bridge.rs index 26225a6..42f59c1 100644 --- a/src/ui_bridge.rs +++ b/src/ui_bridge.rs @@ -1163,9 +1163,18 @@ impl NativeCallable for Function { ("layoutCancels", session.layout_cancels as i64), ("paintCancels", session.paint_cancels as i64), ("paintSlices", session.paint_slices as i64), + ( + "dependencyInvalidations", + session.dependency_invalidations as i64, + ), ] { cx.set_attr(stats, name, Value::Number(value.into()))?; } + cx.set_attr( + stats, + "lastInvalidDependency", + Value::Text(session.last_invalid_dependency.clone()), + )?; return Ok(NativeResult::Return(Value::Object(stats))); } if matches!(self.operation, State) {