Skip to content

Instantiate Repeaters eagerly via an ensure_instantiated pass#11397

Open
ogoffart wants to merge 3 commits intomasterfrom
olivier/ensure-instances
Open

Instantiate Repeaters eagerly via an ensure_instantiated pass#11397
ogoffart wants to merge 3 commits intomasterfrom
olivier/ensure-instances

Conversation

@ogoffart
Copy link
Copy Markdown
Member

Add a new ItemTreeVTable method ensure_instantiated that walks the item tree and calls ensure_updated on every Repeater, Conditional and ComponentContainer. Generated code (Rust, C++, interpreter) implements it by recursing into children after materializing its own repeaters.

Call this repeater instantiation pass from event-loop boundaries (process_mouse_input, process_key_input, draw_contents, show_popup) so init code that reads geometry runs outside any in-flight property evaluation.

The testing backend tracks its TestingWindow instances and runs the instantiation pass on each of them in mock_elapsed_time, so internal tests that mutate a property and then read a layout value behave like a real event-loop tick without having to dispatch a full event.

Adjust two existing tests whose assertions encoded the historical lazy init ordering (callbacks/init, models/if_dirty) and add regression tests for the linked issues.

Fixes: #7402
Fixes: #9498
Fixes: #4522

@ogoffart
Copy link
Copy Markdown
Member Author

This will need more testing and figuring out if this has performance inmpact

Add a new ItemTreeVTable method `ensure_instantiated` that walks the item
tree and calls `ensure_updated` on every Repeater, Conditional and
ComponentContainer. Generated code (Rust, C++, interpreter) implements it
by recursing into children after materializing its own repeaters.

Call this repeater instantiation pass from event-loop boundaries
(process_mouse_input, process_key_input, draw_contents, show_popup) so
init code that reads geometry runs outside any in-flight property
evaluation.

The testing backend tracks its TestingWindow instances and runs the
instantiation pass on each of them in mock_elapsed_time, so internal
tests that mutate a property and then read a layout value behave like a
real event-loop tick without having to dispatch a full event.

Adjust two existing tests whose assertions encoded the historical lazy
init ordering (callbacks/init, models/if_dirty) and add regression
tests for the linked issues.

Fixes: #7402
Fixes: #9498
Fixes: #4522
@ogoffart ogoffart force-pushed the olivier/ensure-instances branch from 814612f to c93614e Compare April 16, 2026 10:43
@ogoffart ogoffart marked this pull request as ready for review April 16, 2026 13:34
Comment thread internal/core/window.rs
) -> Option<T> {
// Must run before entering the redraw tracker scope so init code does
// not attach its geometry reads to it.
self.ensure_tree_instantiated();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we'll end up sprinkling these over time - I can see that we might do this also in the access kit code :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking about it, we probably need to have a property scope, so we don't register any dependency

ogoffart and others added 2 commits April 17, 2026 12:13
Actually remove the call from ensure_updated from the visiting code
Make sure that the dependency are tracked.

Add a test that property accessed in init do not trigger dedraw
@ogoffart ogoffart requested a review from tronical April 17, 2026 10:22
Comment thread internal/core/menus.rs
}

fn update_shadow_tree_recursive(&self, parent: &ItemRc) -> SharedVector<MenuEntry> {
vtable::VRc::borrow_pin(parent.item_tree()).as_ref().ensure_instantiated();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen this twice at least. Perhaps worth a convenience functions on ItemRc? But feel free to ignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants