The Spectrum Dispatch News

technology

Rust GUI Frameworks Like GPUI Struggle With Complex App State Management

A critique examines why GPUI and egui's state models may not scale for large desktop applications, despite their appeal for simpler use cases.

Rust GUI Frameworks Like GPUI Struggle With Complex App State Management

Rust desktop GUI frameworks like GPUI and egui have gained traction recently, with high-profile projects such as Discord announcing a rewrite using GPUI. However, according to a technical analysis on blog.zortax.de, both frameworks have fundamental limitations in their state models that prevent them from scaling efficiently for complex applications.

Rust GUI Frameworks Like GPUI Struggle With Complex App State Management

The core issue centers on a single question: when a value in the application state changes, what code needs to run? According to the critique, GPUI uses a “notify” mechanism that requires developers to explicitly signal when state changes. Since Rust lacks write barriers on mutable references, GPUI cannot detect which fields changed or whether anything changed at all. This forces the framework to re-render views conservatively, similar to how Angular’s zone.js approach works—a system the Angular team acknowledged “has not scaled well” in 2023.

Benchmark results illustrate the performance constraints. In tests with 3,000 live rows, changing a single label takes 8.4 milliseconds when using cached views per row, and 92 milliseconds without caching. The cost scales roughly 3 milliseconds per 1,000 additional rows, following the entire UI tree rather than just the change. By comparison, a hand-written equality guard reduces the cost for identical writes from 7.9 milliseconds to 0.9 microseconds.

Attempts to fix GPUI’s precision by retaining more state between frames create their own problems. Making individual labels separately owned entities with subscriptions and guards transforms the framework from a simple “render as a plain function” model into a manually constructed signal graph—defeating the original appeal of the framework’s straightforward API.

The author notes that while GPUI has a reputation for speed, this largely reflects Zed’s relatively simple UI architecture. Zed’s interface contains only tens of nodes and a few thousand elements, with the text editor implemented as a custom element that bypasses GPUI’s standard layout system entirely. Signal-based frameworks like Floem, Solid, and zgui offer an alternative approach where the framework automatically detects which components read changed values, though the author discloses working on zgui.

Key facts

  • GPUI requires explicit notification when state changes, preventing the framework from automatically detecting field-level changes
  • Changing a single label in a 3,000-row UI costs 8.4ms with per-row caching and 92ms without it
  • Hand-written equality guards can reduce identical-write costs from 7.9ms to 0.9 microseconds
  • Making GPUI more precise requires developers to create separately owned entities with subscriptions and guards, undermining its simple API design
  • Zed’s perceived performance benefits come partly from its simple UI structure, not the framework’s state model

Sources

← All posts