Skip to content

perf(virtual-rows): add El::virtual_rows_append_only() so growing lists read only appended keys - #1802

Merged
Hona merged 1 commit into
devfrom
fix/203-virtual-rows-append-only
Nov 24, 2026
Merged

Hona merged 1 commit into
devfrom
fix/203-virtual-rows-append-only

Conversation

@Hona

@Hona Hona commented Nov 24, 2026

Copy link
Copy Markdown
Member

Fixes #203

Root cause

  • In crates/rune/src/runtime/commit/measure.rs, any El::virtual_rows count change treated the whole list as changed, calling RowSource::key for every row and rebuilding VirtualList's key table and prefix sums in crates/rune/src/el/virtual_list.rs.
  • El::virtual_rows_version promises that count changes are always detected without a bump, so growing append-only lists still paid O(rows) on every append.

What changed

  • Added El::virtual_rows_append_only() (crates/rune/src/el/virtual_rows.rs, crates/rune/src/el/rare.rs, crates/rune/src/runtime/commit/memo_reuse.rs) so a list can promise that a longer count (with unchanged virtual_rows_version, if set) keeps existing keys in order and only appends new rows at the end.
  • Added VirtualList::append_keys and VirtualList::try_append_rows (crates/rune/src/el/virtual_list.rs, wired in crates/rune/src/runtime/commit/measure.rs) to insert only new keys into Places, extend measured/born/row_heights and fresh prefix sums in O(new rows), keep Window::same == false so memo regions update, and fall back to set_keys on duplicate new keys, shrinks, or virtual_rows_version bumps.
  • Added broken-promise guards and debug diagnostics (crates/rune/src/tooling/perf_warn.rs, crates/rune/src/runtime/commit/measure.rs, crates/rune/src/runtime/commit/remount.rs):
    • All builds check the start, midpoint and end of the existing prefix before appending (at most 3 key calls, O(1)) and fall back to a full rekey on mismatch.
    • Debug builds also check the mounted window on append and newly mounted old rows in populate_virtual_children / remount_virtuals, warning once per list via perf_warn.
col()
    .key("rows")
    .w_full()
    .growth(GrowthSpec::default())
    .virtual_rows(s.rows.len(), 24.0, |s: &State, i| s.rows[i].as_str().into(), build_row)
    .virtual_rows_version(s.version)
    .virtual_rows_append_only()

Benchmark & verification

Headless Runtime appending 1 row/frame to a 100,000-row list (50 frames/run, 5 paired alternating runs under --profile perf, all outliers kept; excludes GPU upload and presentation):

Mode Key calls per +1 append (10k / 25k, release) Median frame time (100k rows) All 5 runs (ms/frame)
Default (virtual_rows) 10,001 / 25,001 29.805 ms 26.648, 29.805, 36.941, 27.994, 34.635
virtual_rows_append_only() 4 / 4 0.230 ms (129.7x faster) 0.184, 0.289, 0.222, 0.230, 0.408
  • Regression tests in crates/rune/src/el/virtual_rows_append_tests.rs, crates/rune/src/el/virtual_list.rs, and crates/rune/tests/integration/virtual_rows_append.rs (append_only_reads_only_new_keys_while_default_reads_all failed with 10,001 calls before the fix and passes after).
  • Commands run:
    • cargo test -p rune -p rune-mermaid -p rune-kit --features rune-kit/markdown,rune-kit/mermaid el::virtual_ (43 passed, 0 failed)
    • cargo test -p rune -p rune-mermaid -p rune-kit --features rune-kit/markdown,rune-kit/mermaid virtual_rows_append (1 passed, 0 failed)
    • cargo test -p rune --profile perf --test integration virtual_rows_append_only_public_api_counts (1 passed)
    • cargo test -p rune --profile perf --test integration virtual_rows_append_time -- --ignored --nocapture
    • scripts/file-size.sh (0 errors, 0 new warnings)
  • Not checked on this machine: interactive GPU/window presentation (headless Runtime only; code is platform-independent with no target-specific cfg blocks).

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.

virtual_rows: changing the row count re-reads and copies every row's key, so appending to or filtering a long list costs O(rows) a frame

1 participant