Repository navigation
perf(rune): type-erase Runtime, Measurement, and Cx into non-generic RuntimeCore - #1192
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.
Type-erases
Runtime<S>,Measurement<'_, S>, andCx<S>into non-genericRuntimeCore,Measurement<'a>, andCxCore, removing ~22.5k lines of production code from per-state-type Rust monomorphization with zero public API breakage.Why
Previously, almost all of
crates/rune's runtime, commit/measurement, paint, selection, input, a11y, clipboard, and window sync logic lived insideimpl<S> Runtime<S>,impl<S> Measurement<'_, S>, andimpl<S> Cx<S>. Every distinct app state typeS— in downstream apps, examples, and across every test state struct — re-monomorphized and LLVM-codegen'd ~22.5k lines of runtime MIR, dominating compile times, peak RAM, and.rlib/binary sizes.Architecture
#[repr(C)]layout (crates/rune/src/runtime.rs,crates/rune/src/runtime/init.rs):runtime_core_fields!generates identical#[repr(C)]prefixes forRuntimeCore(244 non-Sfields + 3 hoisted metadata fields:app_ime_comp,app_root,has_playground) andRuntime<S>, terminated by a#[repr(align(16))] pub(crate) struct CoreEndzero-tail-padding sentinel.pubfields stay directly accessible onRuntime<S>, preserving disjoint field borrows (&mut rt.text.atlas, &rt.instances) across internal call sites and externalCompositor<S>apps.assert_prefix_layout::<S>()) verify identical field alignment/offsets, covered byruntime::prefix_layout_tests::shared_prefix_layout_holds_across_state_alignmentsacross(),u8,u128, and#[repr(align(64))].CxCore&Measurement<'a>(crates/rune/src/runtime/cx.rs,crates/rune/src/runtime/driver.rs):CxCoreowns all 18 context fields and methods;Cx<S>is a zero-overhead#[inline(always)]wrapper (preserving#[track_caller]).ViewDriver,AppDriver, andPlaygroundDriverprovide narrow trait-object boundaries so all 4Measurement<'a>impl blocks (~1.2k lines) and 119RuntimeCoreimpl blocks (~20.7k lines) compile once insiderune.playground::Live<S>initialized only inLive::new.crates/rune/src/runtime/api.rs,crates/rune/src/runtime/input/api.rs):Runtime<S>methods delegate toRuntimeCorevia#[inline(always)]one-liners, and non-Sinternal free functions acrossa11y,clipboard,file_dialog,popup_menu,motion_gate,tooling, andwindownow take&[mut] RuntimeCore.Metrics
impl RuntimeCore: 20,657 lines across 119 blocks;impl Measurement<'a>: 1,201 lines across 4 blocks;impl CxCore: 131 lines; non-generic free functions: ~480 lines).Measurementblocks remaining.