Repository navigation
refactor(runtime): group the runtime's private state into subsystem structs - #1234
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RuntimeCoredeclared 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:helloandsettingsproduce byte-identical--snapPNGs and--treeJSON.Before and after
runtime_core_fields!runtime.rsnon-test lines#[path]attributes inruntime.rssize_of::<RuntimeCore>()The groups
treeTreeStatehitHitStatepaintPaintStatemotionMotionStatescrollScrollTablesframeFrameStateTx, wake deadlines, live lane, tracingcommitCommitStatepointerPointerStatekbdKeyboardStateeditTextInputStatehostHostStateEach struct lives in the module that owns it.
Runtime<S>still begins with exactlyRuntimeCore'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 intoruntime/virtual/(virtualis a reserved word) anda11y/.Speed
The field order is memory layout, so this was measured. Two things mattered:
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::buildis 1,146 B smaller). A comment on each says why it is there.Headless frame cost,
--profile perf, 100 alternating pairs pinned to one core on a quiet machine; GPU upload and presentation are outside the number:devdevPaint 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 (
runelib 1,902, integration 428,rune-kit451). Checked for Linux with and withoutdbusand 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.