Skip to content

refactor(runtime): group the runtime's private state into subsystem structs - #1234

Merged
Hona merged 2 commits into
devfrom
group-runtime-core-fields
Nov 19, 2026
Merged

Hona merged 2 commits into
devfrom
group-runtime-core-fields

Conversation

@Hona

@Hona Hona commented Nov 19, 2026

Copy link
Copy Markdown
Member

RuntimeCore declared its state as one flat list of 247 fields. Nothing said which subsystem owned a field, and any function could reach all of them. The 222 private ones now live in 11 subsystem structs, embedded by value; the 25 public fields stay where apps reach them. No public API changes and no behaviour changes: hello and settings produce byte-identical --snap PNGs and --tree JSON.

Before and after

Before After
Entries in runtime_core_fields! 247 36 (25 public fields, 11 structs)
runtime.rs non-test lines 998 515
#[path] attributes in runtime.rs 113 9
size_of::<RuntimeCore>() 18,016 B 17,840 B

The groups

Field Type Fields Owns
tree TreeState 20 nodes, id and path tables, per-commit capability flags
hit HitState 5 the hit lists paint builds: pointer, wheel, overlay, help, drop
paint PaintState 35 paint scratch, reuse record, layer caches, pixel snap, materials
motion MotionState 23 flights, loops, launches, growth stacks, reveals, rewind
scroll ScrollTables 7 scroll states, requests, wheel lock, sticky frames
frame FrameState 19 action queue, pending Tx, wake deadlines, live lane, tracing
commit CommitState 27 dirty flags, layout engine, memo cache, virtual lists, layout callbacks
pointer PointerState 21 position, press, hover, tooltips, touch, autoscroll, drags
kbd KeyboardState 17 focus, modal scope, type-select, held keys, modifiers
edit TextInputState 21 selection, links, caret, IME, spellcheck, clipboard queues
host HostState 29 zoom, titlebar, system settings, window requests, popups, dialogs

Each struct lives in the module that owns it. Runtime<S> still begins with exactly RuntimeCore's layout, and the compile-time proof now compares the offset of every top-level field.

The second commit declares the runtime's modules at their default paths. The nine #[path] attributes left point into runtime/virtual/ (virtual is a reserved word) and a11y/.

Speed

The field order is memory layout, so this was measured. Two things mattered:

  • Constructors. The first sixteen layouts were 2 to 5% slower on paint, and the data layout was not why. Eleven new single-caller new() functions in eleven modules changed how the crate splits into codegen units: the spring glide stopped inlining a hash-map insert, and the paint walk got 5.7 KB of cold code in the middle of its per-node loop. #[inline] on the constructors restored all three hot functions to the baseline's size and instruction count (RuntimeCore::build is 1,146 B smaller). A comment on each says why it is there.
  • Order. The fields the per-node paint and commit loops read are first and together; input, text and host state follow.

Headless frame cost, --profile perf, 100 alternating pairs pinned to one core on a quiet machine; GPU upload and presentation are outside the number:

Scenario Frame vs dev Pairs won Paint vs dev
Layers, 1,500 nodes -0.8% 63/100 -4.25%
Text typing -0.95% 80/100 -0.4%
Virtual scroll -0.5% 67/99 -0.6%
Plain boxes, commit -0.5% 58/100 +1.0%
Spring-animated list 0.0% 50/98 -0.3%
Plain boxes, hover +0.6% 37/100 +1.2%
Idle frame +0.4% 35/99

Paint on the two plain-box scenarios is about 1% slower (0.7 to 2.4 ns per node) and that is real, not noise; the hot functions are the same size or smaller, so it comes from where fields now sit. Four scenarios are faster. Across seventeen layouts the last half percent moved between scenarios without going away.

Verification

macOS: the workspace compiles and the full suites pass (rune lib 1,902, integration 428, rune-kit 451). Checked for Linux with and without dbus and with file dialogs, iOS and wasm. The Apple-only and Linux-only sites the rename touched are in the overlay and window draw paths, the embed host, the Linux primary selection and two macOS tests.

@Hona
Hona merged commit f438ce1 into dev Nov 19, 2026
1 check passed
@Hona
Hona deleted the group-runtime-core-fields branch November 19, 2026 08:02
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