Skip to content

2D virtual windows: canvases and wide tables mount only what's in view, without re-running view #997

Done

Description

@zohu

Summary

virtual_rows windows a vertical list by index. Two common layouts need windowing in two dimensions, and neither can get it today:

  • Infinite canvases / node graphs. Thousands of absolutely positioned items under an app-owned camera (live_offset / live_scale). Only items near the camera should exist as elements. Today the app rebuilds the view with a new set of children whenever the camera moves far enough, so every window change re-runs view and re-subscribes everything still mounted.
  • Wide tables (spreadsheet-like, hundreds of columns). virtual_rows builds only visible rows, but every row builds all of its cells. 40 visible rows × 200 columns is 8,000 cell elements with only a small block on screen, and commit, layout and Live subscriptions scale with all of them. Strata's table view in Virtual lists and grids: a heading row counts as an item, an item's set size replaces its row's, and no row or column index #533 is built the same way (cells inside virtual rows).

Where we hit it (canvas, rev d751f07)

A node-graph canvas with 200 nodes at near zoom, nodes running with progress. Apple M1 Max, --profile perf, 120 frames after warm-up, median of 5 runs: 10.8 ms/frame average, 25.3 ms peaks, mostly view re-runs as nodes enter and leave the window. At 10,000 nodes / 15,000 edges, building everything is not an option. We have not measured a wide table; the numbers above are the canvas case.

What we'd like

  1. A core primitive: an element owning a keyed set of positioned items whose window the app decides, for example El::virtual_items(Rc<dyn VirtualItems>) with version() (called every frame, cheap), keys() (current window, back to front), build(key) (no app state), plus optional mount_budget() and mount_priority(key).
    • A commit that only changes that set behaves like a virtual_rows remount: view does not run and mounted items keep their subtrees.
    • Entering items mount within a per-frame budget, nearest first. Leaving items unmount at once. A focused item stays pinned.
    • Content changes go through a new key plus a version bump.
  2. On top of it, or alongside virtual_rows, a scroll-driven grid for tables: rows × columns with row heights and column widths, windowed on both axes from the scroll offset. Ideally frozen header rows / leading columns, and the row and column indices from Virtual lists and grids: a heading row counts as an item, an item's set size replaces its row's, and no row or column index #533 for accessibility.
  3. Related: One live_text anywhere makes every virtual-window shift run the view #544. A live_text inside a windowed item should not force a full rebuild. We lay it out against its first sampled text and draw the current text.

Result with a patched build (canvas)

The same 200-node scene: 0.93 ms/frame average, 2.3 ms peak. A 10,000-node graph pans and zooms with zero view runs per window change (RUNE_FRAME_LOG commit reasons are only virtual).

Reference implementation of (1) on our fork, reusing the remount move plan: zohu@56d14e65 (based on d751f07, before the newer pins / fill-state work on dev). It does not include (2).

Activity

  1. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    Thanks for the detailed write-up, the numbers and the reference commit.

    I checked this against dev:

    • El::virtualize / El::virtual_rows (crates/rune/src/el/virtual_rows.rs) only window a vertical growth stack inside a scroll viewport, by index. I found no keyed or 2D equivalent in crates/: nothing like virtual_items, a grid source or column windowing.
    • The rune-kit table (crates/rune-kit/src/containers/table/view.rs) builds every cell of each mounted row, so wide tables scale with column count, as you describe.
    • live_offset / live_scale pan and zoom a camera with no view re-run, but changing which items exist still needs one.

    I'm tracking this as a feature request with three parts:

    1. A core keyed, app-windowed item set (version / keys / build, a mount budget with nearest-first priority, focused items pinned). A commit that only changes the set takes the remount path, so view doesn't run.
    2. A scroll-driven grid windowed on both axes, ideally with frozen header rows and leading columns and the row and column indices from Virtual lists and grids: a heading row counts as an item, an item's set size replaces its row's, and no row or column index #533.
    3. A live_text inside a windowed item that doesn't force a rebuild (One live_text anywhere makes every virtual-window shift run the view #544).

    This overlaps #1384 (wrapped grids and horizontal windowing for virtual_rows) but isn't the same, so the two stay separate. Your fork commit (56d14e65, based on d751f07) is a useful reference. dev has moved since then (pins and fill-state work), so any change has to be rebased onto the current remount code.

  2. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    I looked at bringing this in and haven't made a change. It's bigger than one patch should be, and part of it needs a maintainer decision first.

    If you'd like to move part 1 forward, a PR against current dev would be the easiest thing to review. It should follow the conventions in AGENTS.md (feature-owned state, one bullet in changelog/unreleased/, a sibling test file) and come with your paired --profile perf numbers.

  3. zohu commented on Nov 25, 2026

    @zohu
    Author

    Thanks for looking into this. We agree that the keyed virtual_items primitive makes sense as a standalone PR.

    We’ve since ported our implementation to upstream 22ebd7e7. Here’s the patch we use downstream. It shows how keyed items fit into the restructured remount code and includes a paired headless benchmark comparing a window change with a full view rebuild.

    The patch also includes Playground integration and our live_text measurement change. For an upstream PR, we’d keep the scope to the core primitive, leave live_text to #544, and keep the scroll-driven grid as a separate design discussion.

    The canvas timings in the original report were measured on the earlier build.

  4. Hona commented on Nov 25, 2026

    @Hona
    Member

    Thank you for the clear description and numbers.

    Please do not spend time preparing a pull request — as the README notes, this project does not accept external pull requests. We are building the core keyed El::virtual_items primitive ourselves from scratch against current dev, and separately working on column windowing for rune-kit's Table.

    For the third part (live text inside windowed items), recent work on dev already covers keeping live_text on the remount fast path, paint keep, and tabular digits (#1472, #2094, #2105, #2119).

    We will measure our implementation against the scenario and numbers in your description, and let you know here once it lands so you can try it.

  5. Hona commented on Nov 25, 2026

    @Hona
    Member

    Part 1 (core El::virtual_items keyed container) is now on dev in #2236 (2be8844).

    • API: rune::VirtualItems (version, keys, build, plus defaulted mount_budget and mount_priority) and El::virtual_items(Rc<dyn VirtualItems>).
    • Behaviour: version() is checked in O(1) each frame so idle windows do nothing; window changes take CommitKind::Remount without re-running view; staying items keep their NodeId, paint-keep epochs, memo entries, and Live/LiveText subscriptions without calling build; leaving items unmount immediately except an item holding keyboard focus (or a focused descendant), which stays pinned until focus leaves it; entering items mount settled up to mount_budget() per frame nearest-first by mount_priority(key) while rendering in keys() back-to-front order.
    • Example:
    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())
    • Paired --profile perf benchmark (cargo run --profile perf -p rune --example virtual_items_bench, 5 paired alternating runs × 120 frames, 4 entering / 4 leaving items per frame + 1 staying 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

    See the Lists/Virtual items canvas story in examples/playground. Follows spatial canvas culling separated from 1D scroll virtualizers and W3C CSS Containment Level 2 focus pinning.

    Tested headlessly on Windows (unit, runtime, a11y, remount/memo/prune/relayout, doctests, clippy, wasm32 WebGPU/WebGL checks, and --profile perf benchmark), macOS arm64 (unit, runtime, doctest, and --examples --benches --tests check), and Linux aarch64 (--examples --benches --tests check); not viewed interactively in a live GPU window.

    Please try it on dev (2be8844) and let us know if anything is missing or behaves unexpectedly for your canvas. Leaving this issue open for part 2 (column windowing in rune-kit Table).

  6. Hona commented on Nov 25, 2026

    @Hona
    Member

    Wide-table column windowing and frozen leading columns for rune-kit::Table landed on dev in #2238 (73bf4e5b5), along with vertical El::virtual_rows remounts inside El::scroll_xy wrappers and ARIA grid counts/indices (aria-rowcount, aria-colcount, aria-rowindex, aria-colindex) on AccessKit and the web DOM mirror.

    Table::new(|s: &App| &s.table, |s: &mut App| &mut s.table, |s: &App| s.rows.len(), |s: &App, i| s.rows[i].id.as_str().into())
        .scroll_wide(true).virtual_columns(true).frozen_columns(2)
        .column(TableColumn::new("id", "ID").width(80.0))
        .cell(|s: &App, i, col| Cell::text(s.cell(i, col)))
        .build(s, &kit)

    Before / after (10,000 rows × 200 columns of 100 pt, 1,000 × 1,150 pt viewport ≈ 40 visible rows, 42 mounted rows with virtual_overscan(0.0, 0.0), 5 paired alternating runs, --profile perf, headless commit + layout excluding GPU upload/present):

    • Cells built & mounted: 8,400 → 630 (15 columns at start, ~20 mid-scroll).
    • Full commit + layout rebuild (median): 55.76 ms (51.06–56.92) → 4.67 ms (3.72–5.64).
    • Vertical scroll remount (median, 0 view runs): 36.59 ms → 2.37 ms.
    • Horizontal scroll: 0 view runs inside the hysteresis band; crossing a column window runs view once per shift (12.68 ms median per shift across 12,000 pt).

    Follows WAI-ARIA 1.2 windowed-grid attributes and CSS position: sticky / AG Grid pinned-left columns; both builders default off (false / 0), leaving existing tables unchanged. Resizing, header-drag reordering, keyboard focus, and El::caret_browsing(true) stay working while scrolled out of view. See rune-table--virtual-columns in examples/kit-gallery.

    Tested on Windows, macOS, Linux (compile check), and headless Chromium (WebGPU + WebGL2 smoke and ARIA mirror checks); not seen in a live desktop window, real screen reader, non-Chromium browser, or iOS.

    Still open here: a core crates/rune scroll-driven 2D grid / horizontal-axis virtualization primitive (for custom sheets outside rune-kit::Table with zero view runs across horizontal column boundaries), to be designed alongside #1384. Let us know if this table API misses anything your wide-table case needs.

  7. Hona commented on Nov 25, 2026

    @Hona
    Member

    Both main pieces of this issue are now on current dev:

    For a custom wide sheet outside rune-kit::Table, El::virtual_items already supports zero-view-run scrolling on both axes by updating the source from on_scroll_offset (which runs without rebuilding view):

    let sheet = s.sheet.clone();
    col().key("sheet").w_full().h_full().scroll_xy()
        .on_scroll_offset(move |pos: ScrollPos| sheet.set_viewport(pos.offset, pos.viewport))
        .child(el().key("cells").size(total_w, total_h).virtual_items(s.sheet.clone()))

    For part 3, El::live_text inside windowed items already stays on the remount fast path without rebuilding or reshaping tabular digits (#1472, #2094, #2105, #2119). We will not change El::live_text to lay out against its first sampled text instead of its authored placeholder, because placeholder sizing (such as text("00:00")) is how apps reserve width so shorter initial values do not collapse or clip later updates.

    A built-in core scroll-driven 2D / horizontal-axis grid primitive in crates/rune (so custom sheets do not wire VirtualItems manually) is now tracked in #1384 alongside wrapped grids and horizontal virtual_rows.

    Both merges were verified with headless tests and benchmarks only, not in a live window. Please reopen if El::virtual_items or Table::virtual_columns falls short for your canvas or wide sheet on current dev.

    Thanks for the detailed report and numbers.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions