Upstream: crates/rune/README.md § Launching fast at
65f8eb43f710, MIT © Anomaly. Bundled by build-rune-apps; links point at this snapshot or at GitHub at that rev.
Launching fast
A small app puts its first window, with content, on screen about 300 ms after open on Apple silicon.
The full page, with the measurement method, is "Launch fast" on the docs site (site/src/pages.tsx).
Staying fast afterwards is "Fast apps" (site/src/FastApps.tsx) and "Smooth scrolling" below;
scripts/app-audit <repo> greps an app for the patterns they list.
rune::prewarm_gpu()first inmain. On macOS it makes the adapter, device and uber pipeline on a thread while AppKit starts; the first window or overlay opened at launch takes them, waiting if the thread is still working. A second call does nothing. With no window at launch the result is dropped; a window that needs features the prewarmed device lacks gets a new device. Elsewhere it does nothing. The run functions call it too, but only once the event loop starts. It starts on the backend the app draws with by default: on macOS, Rune's own Metal backend (themetal-backendfeature, on by default; an app built withdefault-features = falsegets wgpu unless it adds the feature). An app that opts out withApp::gpu_backend(GpuBackend::Wgpu)callsrune::prewarm_gpu_on(GpuBackend::Wgpu)instead, which chooses the backend and then starts the thread, so it doesn't start on the native backend and start over whenApp::gpu_backendruns; that call afterwards changes nothing.RUNE_GPU_BACKEND=wgpuor=metaloverrides both without a rebuild. A compositor whoseCompositor::featuresasks for more than the native backend offers (TIMESTAMP_QUERYandIMMEDIATES) draws with wgpu instead, every frame: logrune::describe_gpu(frame.device)once to see which backend a window got and why, or setRUNE_GPU_LOG=1.- Precompiled Metal uber shader.
crates/rune/src/uber.metallibis loaded through wgpu's passthrough shaders, skipping WGSL translation and Metal's compile (Renderer::new232 ms to 85 ms on a cold shader cache). The WGSL path is the fallback when the adapter lacks passthrough support, whenRUNE_DISABLE_METALLIB=1, when the fingerprint doesn't match or when Metal rejects the library. Rune's own Metal backend (metal-backend) loadsuber_native.metallib, built from the MSL that backend emits (firstRenderer::new222 ms to 90 ms cold, 4.0 ms to 0.9 ms warm). After editingclip.wgslorshader.wgsl, runcargo test -p rune --lib --features metal-backend precompiled_uber_metallib_is_freshon a Mac. If it says the MSL is byte-identical, paste the printed lines intouber/metallib_hash.rs. If it says the MSL, flags or library hash changed, runscripts/precompile-metal-shaders.sh(needs Xcode's Metal toolchain) and commit both libraries anduber/metallib_hash.rs. Effect, lighting and blur shaders and iOS aren't precompiled; binary archives would need wgpu support. - The first frame draws during window creation on macOS for visible windows (not launcher windows or panels).
The first view build and layout run inside creation, right after the window-created callbacks, so keep the initial
state,
viewandon_windowcheap. - Defer the rest to
on_ready. It runs once per native creation after the first frame is ready (for a launcher, while hidden). A window that isn't on screen (covered, occluded, hidden or on another Space) doesn't wait to draw: it runs at the first frame skipped for that, or a second after the window opens. Captureapp.handle()and callhandle.update(|s, tx| ..)there to start status items, HUDs, secondary windows, network and indexing; updates run on the UI thread even with no window showing. There is no state-level first-frame hook yet. - A launcher can wait for readiness. With
RUNE_READY_DIRset, the process writes$RUNE_READY_DIR/<bundle id>.<pid>(the main bundle's identifier on macOS, else the executable's name) right after its firston_readyreturns, and removes it when it exits normally. It's one line of JSON,{"pid":123,"bundle_id":"com.example.app","ready_ms":412,"rune":"0.1.0"}, withready_mscounted from the process's start; the directory is made 0700 if it's missing. A process killed outright leaves its file, so treat one whose PID isn't running as stale. Without the variable nothing is written. - Keep the first second still. Rune animates nothing then, so every frame is the app's. Land state that
arrives right after launch (a system setting, a first network answer) with
tx.instant(), or don't animate it. One settings window's launch fade drew about 85 frames in its first second instead of 4 to 8, and drawing back to back while the window came on screen made macOS keep an extra window-sized drawable: 14 MB more settled footprint. Rune now holds a new window to two drawables until it rests, or for its first second. - Draw nothing when idle. A due
wake_afteron a resting window runspollfirst and draws only if it returns true, so return false when nothing changed. A custom compositor returnsanimating() == trueonly while it moves (the default is false); a still one lets its window rest too. One settings window went from 77 presents per 20 s idle to none, 2.45% CPU to 0.85%, and 77 MB to 70 MB. - Relaunch in place while developing.
scripts/mac-appswaps a rebuilt bundle in and starts it before the old process quits, so withrune_mac::remember_framethe new window lands over the old one (see "Relaunching a Mac app" below). - Reuse a hidden window.
keep_running()/windowless()plusAppHandle::hide(),show()andopen()(orWindowOptions::launcher_panel()for a retained panel that reveals cached pixels) make a re-summon cost a show instead of a launch. - Measuring: launch with
openon a quiet Mac, interleave base and changed builds for 5 to 10 rounds, and report medians for window-visible and first-content times, cold and warm. Cold means deleting the app's Metal shader caches undergetconf DARWIN_USER_CACHE_DIR:com.apple.metal/<bundle id>and<bundle id>/{com.apple.metal,com.apple.metalfe,com.apple.gpuarchiver}. Read settled memory last. Count frames in the first second after content. Measure idle too: redraws, presents and CPU over 20 s with the window shown and untouched, plus settled RSS and footprint, and countpollreturns separately from frames.
Median ms from open (loaded laptop, 5 interleaved rounds) |
Before | After |
|---|---|---|
| Cold shader cache, content on screen | 599 | 312 |
| Cold shader cache, window on screen | 422 | 277 |
| Warm shader cache, content on screen | 466 | 299 |
Cold shader cache, Renderer::new alone (10 rounds) |
232 | 85 |
Absolute times were high because the machine was busy; the differences are what matter.