Skip to content

feat(virtual): add VirtualItems and El::virtual_items app-windowed keyed container - #2236

Merged
Hona merged 1 commit into
devfrom
feat/997-virtual-items
Nov 25, 2026
Merged

Hona merged 1 commit into
devfrom
feat/997-virtual-items

Conversation

@Hona

@Hona Hona commented Nov 25, 2026

Copy link
Copy Markdown
Member

Refs #997

Adds VirtualItems and El::virtual_items(Rc<dyn VirtualItems>) — an app-windowed keyed container for 2D canvases, node graphs, and LOD scenes positioned under El::live_offset / El::live_scale — that remounts entering and leaving items without re-running view. Part 2 (column windowing in rune-kit Table) stays open on #997.

API

pub trait VirtualItems: 'static {
    fn version(&self) -> u64;
    fn keys(&self) -> Vec<String>;
    fn build(&self, key: &str) -> El;
    fn mount_budget(&self) -> Option<usize> { None }
    fn mount_priority(&self, _key: &str) -> f32 { 0.0 }
}

impl El {
    #[cfg_attr(debug_assertions, track_caller)]
    pub fn virtual_items(mut self, source: Rc<dyn VirtualItems>) -> Self;
}
el().key("canvas").w_full().h_full().clip_soft(0.0)
    .live_offset(&s.cam_offset)
    .live_scale(&s.cam_scale)
    .virtual_items(s.nodes.clone())

Follows the web split between spatial canvas culling (React Flow onlyRenderVisibleElements / XYFlow RFC #4239) and 1D scroll virtualizers, and W3C CSS Containment Level 2 (content-visibility: auto keeps focused elements and focused descendants relevant/mounted).

Architecture

flowchart LR
    V["VirtualItems::version() O(1)"] --> C{"changed / pending / blurred pin?"}
    C -- no --> I["Idle (0 work)"]
    C -- yes --> R["CommitKind::Remount (0 view runs)"]
    R --> L["Leaving -> virtual_culled (instant unmount, unless focused)"]
    R --> S["Staying -> move_slice (keeps NodeId, PaintKeep epoch, memo, Live/LiveText)"]
    R --> E["Entering -> up to mount_budget by mount_priority (VIRTUAL_MOUNT)"]
    E --> F["virtual_items::fill::Fill (Idle | Filling | Waiting | Stalled)"]
Loading
  • Trait & builder: crates/rune/src/el/items.rs (re-exported as rune::VirtualItems and rune::el::VirtualItems), stored on ElCold::virtual_items (crates/rune/src/el/rare.rs), compared in memo_reuse::same_el_cold, and excluded from el_flatten_reusable / windowed_lists.
  • Feature-owned runtime state: single virtual_items: virtual_items::VirtualItemsState field on CommitState (crates/rune/src/runtime/commit.rs), implemented in crates/rune/src/runtime/virtual_items/{mod,fill}.rs.
  • Remount & coexistence: unified Plan::{List, Items} in crates/rune/src/runtime/commit/remount.rs so virtual_items and virtual_rows coexist on CommitKind::Remount; nested virtual containers in entering items fall back to RemountOutcome::Fallback; unmounted containers prune in crates/rune/src/runtime/commit/prune.rs.
  • Focus & a11y: focused focusable(true) items and items holding a focused text_input stay pinned and mounted across omission from keys() until focus leaves, and a11y/tree.rs emits only mounted (+ pinned focused) items without auto-assigning size_of_set / position_in_set.

Paired benchmark (--profile perf)

cargo run --profile perf -p rune --example virtual_items_bench — 5 paired alternating runs × 120 frames, sliding 4 entering / 4 leaving items per frame plus 1 LiveText update, headless Runtime (omitting GPU upload and presentation):

Canvas Mode p50 (ms) p95 (ms) view runs Item builds
200 nodes (40 visible) Full view rebuild 0.237 0.463 120 4,800
200 nodes (40 visible) El::virtual_items remount 0.095 (2.49×) 0.155 (2.98×) 0 480
10,000 nodes (60 visible) Full view rebuild 0.380 0.425 120 7,200
10,000 nodes (60 visible) El::virtual_items remount 0.155 (2.45×) 0.177 (2.39×) 0 480

Example & docs

  • Interactive story Lists/Virtual items canvas in examples/playground/src/virtual_items_story.rs (2,500-node 2D canvas with drag-pan, zoom toggle, mount_budget(12), nearest-first mount_priority, and focusable nodes).
  • Rustdoc with compiled doctest on El::virtual_items, crates/rune/README.md, examples/README.md, and changelog/unreleased/2026-11-25-virtual-items.md.

Not checked interactively in a live GPU window.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant