Skip to content

fix(relayout,kit-gallery): keep resize relayout with fitted overlays/images and virtualize gallery index - #2308

Merged
Hona merged 1 commit into
devfrom
fix/noticed-kit-gallery-resize
Nov 25, 2026
Merged

Hona merged 1 commit into
devfrom
fix/noticed-kit-gallery-resize

Conversation

@Hona

@Hona Hona commented Nov 25, 2026

Copy link
Copy Markdown
Member

Root cause

  1. Resize CommitKind::Relayout bailed out on fitted overlays, aspect_fit, and pixel_aspect (crates/rune/src/runtime/commit/relayout.rs): commit_kind checked self.tree.nodes.iter().all(reusable), which rejected any tree containing an El::anchored_fit overlay (every open rune-kit Select, Combobox, Menu, Popover, HoverCard, or PopupList), an El::aspect_fit element, or an El::pixels picture sizing one side from its aspect ratio. Any such node forced a full CommitKind::Rebuild (re-running view(), flattening, and diffing the entire tree) on every drag-resize frame.
  2. examples/kit-gallery mounted all 183 stories at once in index mode (examples/kit-gallery/src/stories.rs): launching kit-gallery without --scene stacked all 183 stories into an un-virtualized col() (~11,910 mounted nodes), while rune-menu--submenu-small-window (examples/kit-gallery/src/stories/field_menu.rs) unconditionally opened a context menu at (130, 60) with anchored_fit, defeating Relayout on every resize step even when no overlay was opened by the user.
  3. Duplicate sibling keys under kit-root (examples/kit-gallery/src/stories/combobox.rs, stories.rs, inputs.rs, overlays.rs): rune-combobox--searchable and rune-combobox--animated-filter both mounted Combobox::new("model", &s.combo, ...) using the same key and shared ComboboxState, so opening the combobox in index mounted two model-scrim and two model-content siblings under kit-root. Several Dialog, Select, Menu, Popover, and Tooltip stories likewise shared keys ("dialog", "select", "menu", "popover", "tip") and state.

What changed

  • crates/rune (runtime/commit/relayout.rs, runtime/anchor.rs, runtime/commit.rs, runtime/commit/measure.rs, runtime/commit/apply.rs, runtime/commit/remount.rs):
    • fit_anchored records each clamped anchored_fit overlay's authored unclamped CompactStyle into Measured::above_fit_styles -> Reuse::above_fit_styles (empty vec / zero allocation when no overlay is clamped).
    • Measurement::relayout restores any clamped above_fit_styles and resets aspect_fit nodes to fit_room before calling solve, so both re-fit cleanly against the new viewport without running view() or flattening.
    • commit_kind keeps CommitKind::Relayout whenever pixel_aspects_unchanged(&self.tree) holds, rebuilding only when a picture's decoded ratio actually changed.
    • Added regression tests in crates/rune/src/runtime/tests/relayout.rs verifying 0 view runs and exact layout parity with a full rebuild for aspect_fit, clamped/unclamped anchored_fit overlays with nested submenus, and unchanged vs changed pixel_aspect.
  • examples/kit-gallery (src/stories/index.rs, src/stories.rs, src/main.rs, src/stories/combobox.rs, src/stories/field_menu.rs, src/stories/inputs.rs, src/stories/overlays.rs, src/stories/table.rs, scripts/combobox-animated-filter.json, src/gallery_tests.rs):
    • Virtualized index in src/stories/index.rs with a scroll container and virtual_rows so only visible stories + overscan mount (~314 nodes vs ~11,910), collecting open overlays separately under kit-root.
    • Scoped menu_submenu_small_window's default anchor point to its own scene so it no longer opens a stray menu in index.
    • Gave every story distinct overlay keys and separate ComboboxState fields (combo, combo_animated, combo_localized) and tagged table_menu by story; added standing tests in src/gallery_tests.rs asserting virtualization, zero-view relayout on resize, and zero duplicate sibling keys across every story and every open overlay in index.

Headless drag-resize benchmark (--profile perf, rune/frame-profile)

Paired, alternating runs (5 pairs = 10 runs, 60 drag-resize steps 800x560 -> 1220x800 -> 800x560 at 1x scale, reported by median with p90 and worst-frame outlier kept; headless measurements exclude GPU encode, upload, and presentation):

Scenario Metric Before After
kit-gallery index (closed) Nodes / views (60 steps) 11,910 / 62 314 / 3
Whole frame med / p90 / max 32.55 / 34.87 / 50.77 ms 0.405 / 0.519 / 2.15 ms
Stages med (commit / view / layout / paint / apply) 21.73 / 3.99 / 4.65 / 8.11 / 5.98 ms 0.283 / 0.000 / 0.201 / 0.102 / 0.058 ms
kit-gallery index (combobox open) Nodes / views (60 steps) 12,108 / 62 398 / 4
Whole frame med / p90 / max 34.90 / 37.13 / 55.53 ms 0.453 / 0.586 / 3.07 ms
Stages med (commit / view / layout / paint / apply) 23.83 / 5.49 / 4.68 / 8.33 / 6.19 ms 0.299 / 0.000 / 0.202 / 0.132 / 0.067 ms
Settings-like form + open Combobox Nodes / views (59 steps) 125 / 59 125 / 0
Whole frame med / commit med / max 0.262 / 0.152 / 0.718 ms 0.165 / 0.062 / 0.291 ms
10,000-row virtual_rows + open Popover Nodes / views (60 steps) 178 / 60 178 / 9
Whole frame med / commit med / max 0.723 / 0.414 / 1.041 ms 0.624 / 0.334 / 1.677 ms
aspect_fit + pixel_aspect page Nodes / views (59 steps) 23 / 59 23 / 0
Whole frame med / commit med / max 0.256 / 0.053 / 0.475 ms 0.245 / 0.045 / 0.313 ms

At 0.40–0.45 ms median CPU per resize step (p90 0.52–0.59 ms, worst 3.07 ms on virtual-window growth), kit-gallery and all measured app shapes stay well inside 60 Hz (16.7 ms), 120 Hz (8.3 ms), and 240 Hz (4.17 ms) CPU budgets, leaving GPU upload/presentation under ~1 ms.

Not checked

  • Live interactive desktop window drag-resize and GPU presentation pacing (all checks were headless).

…images and virtualize gallery index

Keep CommitKind::Relayout active across viewport resizes when trees hold
El::anchored_fit overlays (saving and restoring unclamped styles before
fit_anchored re-clamps), El::aspect_fit elements (restoring fit_room before
solve re-fits), or El::pixels pictures whose decoded aspect ratio is unchanged.

Virtualize examples/kit-gallery's default index with virtual_rows so only
mounted stories build (~314 nodes vs ~11,910), stop menu_submenu_small_window
from opening a stray context menu in index mode, and give every gallery story
unique overlay keys and combobox state so opening overlays never mounts
duplicate sibling keys (model-scrim, model-content, etc.) under kit-root.
@Hona
Hona merged commit 071fa97 into dev Nov 25, 2026
1 check passed
@Hona
Hona deleted the fix/noticed-kit-gallery-resize branch November 25, 2026 14:10
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