Repository navigation
New blog: Advice for the next 100 Rust GUIs - #159
Conversation
When published, will close #158
|
|
||
| Adoption of Rust UI in the past few years has been slow. | ||
| Few flagship apps use Rust for their UI. | ||
| One of the most notable is the Zed editor, built on their own GPUI framework. |
There was a problem hiding this comment.
Zed is a good example. Some other larger projects using rust in production: Warp, System 76's Cosmic, and Prime TV.
| Few flagship apps use Rust for their UI. | ||
| One of the most notable is the Zed editor, built on their own GPUI framework. | ||
| It proves that shipping Rust UI is practical, and indeed, GPUI is emerging as a major choice for AI-driven rewrites, most notably Discord. | ||
| My personal sense is that GPUI is well suited to the Zed use case, and shipping in a real project boosts its visibility and credibility quite a bit, but it’s not necessarily the ideal choice for more general purpose applications. |
There was a problem hiding this comment.
I would expand on why you think GPUI may not work well for a rust app.
| Writing Rust code is harder than languages more traditionally used for UI (TypeScript, Kotlin, Swift), and finding engineers skilled in both Rust and UI is challenging. | ||
| But AI is changing the game. | ||
| There’s [evidence][How does programming language affect token efficiency and correctness?] that the LLM cost of writing Rust code is not significantly higher than other languages, and there is reason to believe that in large codebases, Rust will be more maintainable because its type system helps enforce invariants. | ||
| So if all languages have roughly the same cost, then why not go with one that has a dramatically better combination of safety and performance? |
There was a problem hiding this comment.
Maybe one more reason is that there are many bindings to existing well established guis e.g. flutter/qt/the dom/ etc.
| My 2022 blog post had a large section on “native,” first pointing out that the term has no clear meaning, and more broadly pointing out that “native” UI toolkits are simply choices among many, and should be evaluated on the important quality criteria. | ||
|
|
||
| I think this is largely still true, but it depends greatly on which platform is being targeted. | ||
| Windows still has no clear native choice (see [Microsoft Hasn’t Had a Coherent GUI Strategy Since Petzold]) and on Mac there is a bit of fragmentation between AppKit and SwiftUI. |
There was a problem hiding this comment.
Even native is getting rust options. E.g. windows-reactor
| Writing Rust code is harder than languages more traditionally used for UI (TypeScript, Kotlin, Swift), and finding engineers skilled in both Rust and UI is challenging. | ||
| But AI is changing the game. | ||
| There’s [evidence][How does programming language affect token efficiency and correctness?] that the LLM cost of writing Rust code is not significantly higher than other languages, and there is reason to believe that in large codebases, Rust will be more maintainable because its type system helps enforce invariants. | ||
| So if all languages have roughly the same cost, then why not go with one that has a dramatically better combination of safety and performance? |
There was a problem hiding this comment.
"So if all languages have roughly the same..." This would be a great lead into the native section
| It seems to be used in the majority of new Rust UI toolkits. | ||
| In addition, to help mitigate the risk of monoculture, Cosmic Text is a viable alternative. | ||
|
|
||
| AccessKit was just getting started in 2022, but is now solid infrastructure as well, and used by most UI toolkits. |
There was a problem hiding this comment.
Accesskit is quite solid. The api is a bit annoying, but it is certainly the best option at the moment. Many rust uis have some accessibility support, but are certainly lacking. Some frameworks e.g. egui even slow down while voice over is enabled with an animation on screen. I am not sure what the exact reason for lackluster support is but certainly an area that needs improved in the ecosystem.
| This is absolutely something we should build, ideally as a high quality community project rather than something with dozens of vibe-coded forks. | ||
| But even in the latter case it’s better for it to exist than not. | ||
|
|
||
| Discussion question: talk about winit stalling out? |
There was a problem hiding this comment.
Winit devlopment remains quite active. I think slint is driving most of it. I think focusing on the winit gaps would be more productive.
There was a problem hiding this comment.
Oops, didn't mean to leave this in. I think I'll just take it out, as I don't have an informed critique of the current state of winit.
| Immediate mode is very appealing because it’s less total code and seems quite a bit simpler. | ||
| And for some applications (most especially development support for games) it works well. | ||
| However, I am concerned it won’t scale especially well. | ||
| In short, it’s good at the first 90%, but it makes the second 90% harder. |
There was a problem hiding this comment.
Yes, intentional.
| However, I am concerned it won’t scale especially well. | ||
| In short, it’s good at the first 90%, but it makes the second 90% harder. | ||
| To be considered really production-ready, it has to establish stable widget identities to build and update the accessibility tree, it has to reliably cache expensive intermediate artifacts such as text layouts (simple immediate mode often gets around this by cutting corners, which is fine for gamedev). | ||
| And of course, it pulls strongly towards a model of re-rendering everything every frame rather than exploiting layers in the compositor. |
There was a problem hiding this comment.
The egui readme has a section on the advantages/disadvantages. May be worth linking to.
| To be considered really production-ready, it has to establish stable widget identities to build and update the accessibility tree, it has to reliably cache expensive intermediate artifacts such as text layouts (simple immediate mode often gets around this by cutting corners, which is fine for gamedev). | ||
| And of course, it pulls strongly towards a model of re-rendering everything every frame rather than exploiting layers in the compositor. | ||
|
|
||
| For this reason among others, I am not impressed by the choice of the [ArtCraft] projects to use egui. |
There was a problem hiding this comment.
People who are writing apps rarely know enough to make a truely informed choice. I think most people use reddit to get reccomended egui/iced/or gpui. Perhaps there should be a site to guide people to the right framework(s) with a set of questions. Or they just let the ai pick I guess?
There was a problem hiding this comment.
Picking deps is a hard problem. Hopefully this blog will, at the very least, serve as input to the AI to help it pick.
|
|
||
| Having a good spec at the interface between design and execution is critically important. | ||
| As a general strategy, I suggest adapting web standards, but not following them slavishly. | ||
| Web standards are an impressive and important artifact. |
There was a problem hiding this comment.
The standards are a great thing to have. But the magic of the spec is the WPT tests.
| That said, strictly adhering to web standards has serious downsides. | ||
| DOM is slow and memory-intensive; a lighter weight tree representation with a bulk mutation interface might serve the need of GUI apps better. | ||
| Full CSS style resolution and layout is also expensive, though CSS is a rich and powerful way to describe styling. | ||
| A subset of CSS carefully curated for efficiency might be useful. |
There was a problem hiding this comment.
There may be room to move simpler/faster layout algorithms into larger layout crates like taffy so people can have the best of both worlds when they know they can use simpler algorithms. Currently most crates seem to be split into either css layout or simple bare bone layout.
There was a problem hiding this comment.
I agree but in general am painting in broad strokes, and that sounds like a detail.
Of course, another detail is that "CSS layout" is a lot of stuff, some of which is very crufty and not relevant to non-browser UI (eg floats). I think the general suggestion of "carefully curated CSS subset" holds up pretty well as is.
| Blitz, as a modular browser engine, is well placed to serve as the cornerstone of hybrid approaches borrowing heavily from Web specs, but also adapting them to be higher performance and more tightly integrated with platform capabilities. | ||
| As just one example, it’s possible to start with Stylo as the CSS selector engine, and then replace it with a leaner, more efficient CSS engine if that proves to be practical. | ||
|
|
||
| One good example of separation of concerns into smaller modules is the Xilem/Masonry split. |
There was a problem hiding this comment.
It is usually the correct choice to split out the state framework from the actual retained implementation which is exactly what the web has been doing for years. However most crates seem to roll their own element implementations regaurdless of whether they split the state framework from the elment implementation. Either the foundation is not strong enough or people are just feeling ambitous.
| The Xilem reactive layer was designed to be independent of the actual elements it controls, and indeed it has instantiations both for DOM (which, among other things, is the infrastructure for the [squircle] interactive demo) and Masonry widgets. | ||
| Masonry, on the other hand, was designed to be independent of the reactive layer and indeed the language for the layer above it. | ||
|
|
||
| By contrast, SwiftUI mashes together the low level widget implementation, the reactivity framework, and the language as well; LLVM reflection from the Swift language is part of the execution engine. |
There was a problem hiding this comment.
I think there are some rust frameworks that do this. Maybe worth naming them?
There was a problem hiding this comment.
Makepad comes to mind, but it's not really my goal to name and shame. I wrote this because readers will likely be familiar to SwiftUI and receptive to criticism.
| Obviously SwiftUI has had a lot farther reach than Xilem, but my argument today is that we should reconsider assumptions as things are rapidly changing. | ||
|
|
||
| ### Optimization opportunities | ||
|
|
There was a problem hiding this comment.
This is quite basic but most slow guis seem to respond to events with one to many itterations through there widget tree.
There was a problem hiding this comment.
My basic point, which I hope is clear enough but maybe can be emphasized, is that by splitting design and execution, the latter becomes just a computer science problem and any reasonable effort to optimize it will take care of stuff like that.
If you don't, then the implementation may be constrained to inefficient choices. An example that comes to mind is GeometryReader in SwiftUI potentially taking multiple cycles to converge. This might be worth working into the text.
| * Use well-defined specs when available. | ||
| * Find ways to work well with open source. | ||
| Work with upstream but don’t spam them with slop PRs. | ||
|
|
There was a problem hiding this comment.
Maybe a section of blockers for the general rust gui ecosystem? Any language issues that make it hard, missing libraries/integration, etc. Areas where contributors are needed. Do any projects need funding etc.
There was a problem hiding this comment.
I think that would be useful, but probably out of scope for what I want to write about just at the moment. My goal in this blog post is to provoke conversation.
Thanks to Austin for the review. I also did a read-through aloud, and am reasonably confident.
When published, will close #158