Galaxy Shell / docs
Docs / Decisions and plans

Performance: React, Electron and Smithay (the part that did not land)

openspec/changes/performance/design.md · Edit on GitHub ↗

This document records decisions, plans or evidence from a project stage. It does not imply that every item is implemented or validated in the current version.

On this page

Performance: React, Electron and Smithay (the part that did not land)

The landed part and the current rules are in openspec/specs/performance/spec.md. The sections below are the original text of the doc, unchanged.

Potential and limits

The architecture lets us aim for a fast-responding interface with fluid animations while keeping the visual components in the web. Electron brings the cost of Chromium and its processes, especially in memory and startup; that cost alone does not determine interaction latency. The result depends on hardware, driver, resolution, scale, content and the work each thread runs.

The current direction keeps the chat, bars, widgets, controls, custom window frames and the overview interface in HTML/CSS/React. Smithay composes buffers, transforms windows and handles focus and input. External applications produce their own surfaces; they are not rendered inside Electron. Historical native elements that are still present do not prove that the visual migration is finished. See the rendering decision.

Separating the compositor, the host and the core helps to spread the work and to recover components. It does not remove contention for CPU/GPU, communication, copies or failures. There is no proof of end-to-end zero-copy, of superiority over Tauri, or of performance parity between nested execution and direct DRM.

The wait for the model must be measured separately from the local visual response. A field can respond quickly while an AI answer takes seconds. The interface can also add delay after the core has already received the result.

Findings in the implementation

The priorities below are proposed for investigation and correction. This document implemented no optimization. Impacts are inferred from the work seen in the code, with no measured CPU, memory or latency numbers.

P1: full state every 600 ms

In vendor/interface/host/host.js, poll() queries /api/state every 600 ms. There is protection against overlapping queries, but not against repeated work when nothing changed. In web-shell/core/server.js, this route serializes store.state, the full interface bundle, the candidate, models and other metadata. So stable history and assets cross HTTP and JSON parsing again.

publicState() rebuilds the inline documents of all non-archived conversations, and postState() sends the whole set to the iframe, even when the active conversation did not change. This adds string building and cloning through postMessage. The bar also uses the host with polling, although it does not need the full history for its function.

The interval can add a wait close to 600 ms to a change that depends only on the next query, on top of execution, transport and presentation. It is not a hard limit: explicit queries can bring it forward, and load or throttling can extend it. This interval does not measure the latency of local typing.

Proposal: split light state, active conversation content and assets by revision; publish authenticated invalidations and fetch only what is needed; keep a full resynchronization after reconnection. Do not assume that the existing change SSE (Server-Sent Events) stream already provides general conversation events. Measure bytes per query, queries per second, serialization/parsing time and core → UI delay before and after.

P1: synchronous reconciliation proportional to history

vendor/interface/ui-src/app.jsx calls flushSync on every window.shell.onState. Conversation.render() walks all messages; for each one it looks for the surface with find. The lookup cost can reach O(M × S), with M messages and S surfaces. synchronizeOrder() (removed on 2026-11-05, openspec/specs/motion/spec.md) walks the messages again, and the anchor search reads element geometry until it finds the visible part.

Stable keys and moveBefore keep the inline contexts when possible (since 2026-11-05, openspec/specs/motion/spec.md, through keepFramesOnMove on React-owned articles). This is a real benefit: an update is not the same as recreating all the iframes. Even so, keeping the DOM does not remove reconciliation, layout reads or building the data.

Proposal: avoid publishing unchanged state, index surfaces by ID, update only the changed messages and evaluate asynchronous rendering for updates after startup. Synchronous startup is part of the preview and error rejection contract; do not remove flushSync indiscriminately. Virtualization must preserve selection, anchor, search, accessibility and component state, with an explicit contract for suspension and resumption.

P1: continuous work and GPU wait in the compositor

In native/smithay/src/drm.rs, the backend uses OutputDamageTracker, but it calls render() again on VBlank and keeps a 16 ms timer. active and pending prevent improper submissions, but there is no exit condition there based on an unchanged scene before building the elements and requesting a buffer. Damage tracking does not mean the whole loop stops working at rest.

The path also runs rendered.sync.wait() before it hands the buffer to KMS. This synchronous wait can occupy the event path while the GPU finishes. The size of this effect must be measured on the real hardware. VBlank already triggers the next frame: it would be wrong to infer a 60 fps ceiling from the 16 ms timer alone.

Proposal: measure idle CPU, scene build time, GPU wait and real cadence; study scheduling driven by damage, animation and input. Evaluate fences only with validation of the driver and the buffer protocol. Preserve frame callbacks, cursor, screencopy, session resume and correct presentation. Do not remove the synchronization to get an artificially better number.

P1: client buffers through wl_shm

Found on 2026-11-04. The compositor announces no linux-dmabuf, so the Electron host and every other client hand over CPU-visible memory that the compositor uploads to a texture. The evidence and the plan are in glass from the alpha channel. Phase 1 of that plan adds linux-dmabuf. On a full-window animation at 1920x1080 in a test compositor, the Electron tree went from 18% to 30% of a CPU down to 9% to 15%, and the compositor from 9% to 13% down to 6% to 10%. Small damage showed no gain. The session in use takes it at the next login, and the real desktop is not measured yet.

P1: Smithay query at 10 Hz

web-shell/core/smithay.js queries the state over the socket every 100 ms. The protection against overlap limits concurrency, but it keeps the queries going even without changes. Validation and update process windows, outputs and associations. This adds idle activity and a cadence of its own for observing the desktop, different from the physical input response in the compositor.

Proposal: measure queries per second, bytes, CPU and update delay for different numbers of windows; consider notifications or adaptive polling with resynchronization. Do not increase the interval without checking window discovery, focus, associations and action response.

P2: panels, timers and web processes

web-shell/desktop.cjs creates separate surfaces for chat, wallpaper, bar and panels according to the configuration. The cost must be measured over the whole process tree; counting only the main process, or assuming one process per iframe, leads to wrong conclusions.

The panel registry is refreshed every second. web-shell/core/web-panels.cjs reads assets, validates JavaScript with vm.Script and computes revisions; panel-windows.cjs also measures geometry every 250 ms for panels with fit_content. The host queries /api/web-panels every two seconds, and this route also refreshes the registry in the core. There are other timers in the host for metrics, clock, battery, connectivity and panel listing.

Proposal: cache by revision with reliable invalidation, change notifications and size observation where applicable. Measure hidden work before changing cadences. Do not remove the path, size or syntax checks to speed up the refresh. Do not assume that Chromium's automatic throttling suspends all hidden work.

P2: inline components mounted outside the visible area

Conversation mounts the surfaces of the active conversation in iframes, with no full virtualization and no explicit policy to suspend them outside the visible area. web-shell/core/surfaces.js limits publishing to 16 surfaces per conversation; this limit is not a CPU or memory budget for their JavaScript.

Proposal: compare static and animated content with 0, 8 and 16 surfaces, inside and outside the visible area. Define state preservation before unmounting components. Do not assume a separate process per iframe, or protection against excessive consumption just because a sandbox is present.

P2: persistence grows with the profile

web-shell/core/store.js, in save(), clones the whole state with structuredClone and queues its write. In server.js, tool events also call save(). The queue preserves ordering, but an intense sequence of events and a large history can raise the cloning cost and pile up writes.

Proposal: measure duration, size and queue depth. Evaluate incremental persistence or batching of transient status while keeping the required durable points, journal, recovery and consistency. Do not trade durability for speed without defining the failure semantics.

P2: the text answer is merged when the turn ends

The event handler in web-shell/core/server.js updates tool status and, on session.idle, fetches runtime.history() and merges the messages. This path has no incremental publishing of text deltas into the conversation. So the time to first visible text cannot be attributed only to model speed or to Electron.

Proposal: measure separately the first provider event, completion, history fetch and presentation. If text streaming is implemented, group updates by interval/frame, without triggering a full render per token, and reconcile the final result while keeping cancellation and continuity.

Proposed targets

These are initial goals for a reference machine that is still to be recorded. They are not performance criteria that are already approved or reached. Resolution, scale, monitor refresh rate, power mode and load are part of each result.

Dimension Initial goal How to interpret
Local input to visual response p95 below 50 ms Typing, click and palette; separate JS processing from physical presentation
Animations at 60 Hz Cadence of 60 fps, budget of 16.7 ms per frame Total budget, not fully available to JavaScript; record delays and dropped frames
Animations at 120 Hz Investigate a cadence of 120 fps, budget of 8.3 ms Exploratory goal that depends on hardware, driver and compositor; no guarantee today
Idle Minimize CPU and wakeups “Close to zero” is a direction, not an approved threshold; measure before fixing a budget
Memory Stabilize after repeated cycles of use Record baseline and peak; do not invent a limit in MB before the first measurement
Startup Measure until the interface is usable and until the core is ready, separately Tell warm cache from cold, and preparation/build at login
Long history Keep the interaction goal with controlled resource growth Compare fixed loads and check that inline state is preserved

The minimum sample of 100 interactions serves as an initial baseline; widen the collection for decisions close to the threshold, because the tail estimate can vary a lot.

p95 is the value below which 95% of the samples fall. Also publish the median, p99 when there are enough samples, the maximum and the sample size. Average FPS alone can hide noticeable pauses. An animation can keep its cadence and still show delayed input.

Work order and preservation criteria

First get a baseline for transport, rendering, idle and memory. Then reduce retransmitted state and commits without changes, then review DRM scheduling with its own evidence. Investigate panels and persistence as the profiles show cost. Only then evaluate more complex virtualization or an alternative graphics transport.

Keep the sandbox, context isolation, CSP, the host/HTML boundary, the protected send control, the journal and recovery. Reducing isolation or drawing a second native UI in Smithay is not part of the plan. Replacing Electron, adopting offscreen rendering or using Wasm is justified only by a measured bottleneck that the change can address.

Each optimization must repeat the relevant load and check the state of inline components, draft, focus, scroll, selection, reload and recovery. Report separately the proof in the browser, in the Electron host and on the real desktop. A code review or a passing functional test does not validate the performance goals.

Sources and validation status

Independent technical review done by subagent gpt-6-luna, reasoning high, on 2026-10-27. The reviewer analyzed the implementation and confirmed the paths for full state, synchronous rendering, Smithay IPC at 10 Hz, panel refresh and mounted surfaces. The main analysis added the DRM path, persistence and merging of the text at the end of the turn. The findings were checked against the code and consolidated in this document; the review does not certify performance at run time. No performance test ran during the original documentation analysis. The later round of session observation and microbenchmarks is in initial baseline.

First batch implemented

See transport and refresh fixes for the implementation, the before/after comparison and the limits. The findings above describe the original base; that later record shows what has already been handled.