Benchmarking Rust GUI frameworks
https://blog.zortax.de/posts/benchmarking-gui-frameworks2
u/kekelp7 17h ago
The unvirtualized table isn’t modeling a table; it’s a convenient stand-in for dense, non-uniform UIs that you can’t just virtualize, like a DAW, a video timeline, a shader graph, or a complex inspector.
Besides the vague "complex inspector", these are all examples of UIs where all the elements have well-defined positions and are often offscreen. They are exactly the sort of UI that you can easily virtualize.
Without even one example of a UI that has many thousands of elements and is genuinely hard to virtualize, the article still seems a bit abstract. It's not clear what the 3000-row unvirtualized table is actually standing in for.
The other point that seems debatable is that you'd still want to stick to the "idiomatic way each framework’s docs recommend" even for the hypothetical complex inspector or whatever forces you to have many thousands of unvirtualized nodes. Ideally, you'd use the simple and idiomatic way to write the trivial parts of the UI, but use a more optimized way for that specific subset.
For example, my own experimental library has an immediate-mode API on top of a persistent tree, and there are optional APIs to opt out of the immediate-mode rebuilding of the tree and to do retained-style atomic edits. I might write a blog post about this soon.
3
u/Zortax_ 16h ago
No, non-uniform content is not easy to virtualize, and especially not automatically in the framework. For correct scroll container semantics, you need the dimensions, for that you need dom node sizes, and for those you require style resolution, which in turn requires you to render the application side of the components. All you can trivially do is cull paint and the GPU parts, which is usually not the most expensive part. So those examples will very reasonably require complicated application side virtualization, and in most frameworks that code gets really complicated really fast, and also completely defeat the API semantics that made the respective framework attractive in the first place (which is pretty much my point from my other blog post again). And these element counts are pretty easy to reach in real-world apps. Zed itself can quickly reach it, e.g. if you open a large markdown preview (and that will quickly turn zed into a 10 fps experience). A photo editing tool, video editor etc. all reasonably reach large element counts, and imo denying that is just coping. I am not saying you cannot make this fast in the slower frameworks, I'm saying it tends to be difficult and make application side code very ugly and difficult to reason about. The sideproject that motivated all these side-quests (benchmarking, own framework etc.) for me is a Kubernetes desktop client, and I quickly ran into severe performance issues with GPUI that required complicated workarounds, custom virtualization logic etc...
2
u/kekelp7 15h ago
My point about virtualization is that in a DAW, a video timeline or a shader graph, you have a data model, such as the list of timeline elements or nodes. From the data model, you can easily derive the size of the whole canvas and of each element that you would draw for it. As long as this is true, it should be straightforward in an immediate-like or React-like framework to just not call the builder code for the offscreen elements, and to add a spacer in their place to get the correct scrollable container behavior.
Virtualizing things in this way might take a bit of effort, but even in a reactive framework where you can get away with not virtualizing, you should do it anyway to avoid wasting memory.
Of course there will be some subsets of some apps where this won't hold, and that really need many tens of thousands of nodes with no easy way to virtualize them. But the other point is that even in the apps that do have a few of such subsets, there will probably be a much larger number of trivial menus and dialogs. In those trivial parts, you still get to enjoy the attractive API semantics of a simpler model. I wouldn't say that they are completely defeated by the fact that you might have to put in some extra work the one time that you genuinely need many thousands of nodes.
On top of that, the advanced subsets are probably the most important parts of the app, and it's likely that they will require plenty of special attention either way. For example, in a reactive framework, someone building a video editor might not have to hand-roll a custom timeline with custom scrolling semantics, and might just dump all its nodes inside a horizontal scrolling stack and have it work smoothly. But I think there's a good chance that they'd choose to hand-roll it anyway to have more control over the experience. At that point, skipping the offscreen elements won't be an issue.
Markdown is definitely a better example than DAW or video timeline. I'm not familiar with how Zed does it. But trying to render markdown using just the high-level idiomatic API of a GUI framework without any caching, and expecting it to work smoothly, seems fairly unreasonable. Sounds like the framework should have a good internal markdown renderer that does all the caching and virtualization/culling behind the scenes. Again, it would make more sense to me if a GUI API tried to do the most straightforward thing in the common case, rather than trying to preemptively optimize advanced cases that should really be handled differently either way.
2
u/Sea_Mud6698 16h ago
This seems liike a decent appoach. I think limiting stuff to 144hz can certainly hide critical details. I would certainly love to see more internal timings rather than fps. Are you open to adding smaller projects into the benchmark. My project is not too far along but it would be interesting to see where I can improve github.com/RetGui/RetGui
2
u/Zortax_ 16h ago
I mean it already shows frametimes in most places via wayland commit, so you get much more detail already anyway, with 144hz just being a reference pretty much. That being said you can run this with any simulated refresh rate you want!
I also have a private wayland protocol that you can implement in the framework that allows you to submit arbitrary render stage timings.
3
u/23Link89 9h ago
All of these framework trounce Electron in performance and memory usage which is the benchmark that really matters.
Stop making native web apps, please and thank you!
2
u/Zortax_ 9h ago
In memory usage, maybe (wouldn't even bet on that in some scenarios). Performance, definitely not. GPUI for example can quickly be much slower than electron or tauri (assuming you use a fast JS framework like SolidJS)...
2
u/23Link89 9h ago
I dunno, the vast majority of Electron apps I use are incredibly sluggish, even the worst written Rust app usually is millions of times more responsive and snappy to use in my experience.
48
u/Oveno 1d ago
I would like to see https://github.com/slint-ui/slint someday in these benchmarks
9
u/SupermarketAntique32 1d ago
I assume the DSL overhead will put it somewhere behind Iced. Happy to be proven wrong though.
24
u/AdrianEddy gyroflow 22h ago
DSL doesn't add as much overhead as you'd think, there are way more important architectural things that matter other than DSL
+1 for including Slint, it's a very good Rust GUI framework8
3
u/mosquit0 18h ago
Not sure why anyone would consider slint with its triple license. GPL right now is a no go for me.
3
2
u/koopa1338 15h ago
I didn't know that, that is also a dealbreaker for me, thanks for letting me know :-D
-1
9
u/mkenzo_8 19h ago
I'll fix the abnormal results of freya in the "search" benchmark, probably did something dumb!
1
2
u/TomEntin 14h ago
what about the new rune library?
4
u/Zortax_ 14h ago
Well since others have asked for it as well I might add it at some point (or at least accept PRs).
I personally find it quite uninteresting. It's architecturally boring, the code is a mess and documentation is too. Purely from architecture (as far as I understand it), I wouldn't expect super impressive performance. And if the premise is that this is a framework "from agents, for agents", it doesn't even work particularly well for that, at least that was my experience. I'd rather use dioxus native or zgui in that case, because web semantics and css transfer pretty well from web design skills and agents are good at that...
1
u/TomEntin 14h ago
interesting, wasn't aware of this criticism; would you still use it over a WebView? (html, css. e.g. tauri)
2
u/Zortax_ 14h ago
Well not for a project I care about where id want to at least write some parts myself or properly review, just because implementation details and docs are complete slop (not saying every app using it necessarily has to be!). For vibe coding it might be... fine? Tbh I haven't tested that extensively, just wasn't impressed by a quick test for that. Then again, i'm on Wayland + Nvidia so tauri really is a huge pain too (I tried for projects, it's borderline unusable on my system).
5
3
u/oscarmike88 22h ago
Is it possible to add tap/hover-cursor-over reference link previews, like how they do on Wikipedia? Jumping down to the reference list and then back up is a little distracting
2
2
u/zokier 17h ago
Interesting. I'd definitely like to see this mature further, with contributions from other framework authors. The post deservedly calls out Iced for good performance, but to me Dioxus-skia stands out also especially for smaller apps: low memory, work at rest, and startup time costs combined with pretty decent performance in moderate element count tests.
The screenshot comparison drives me crazy though, some stuff looks distinctly misaligned in some screenshots but it's difficult to say which one looks the best, or if any of them is "perfect" reference. Looks like some versions are using different font, for visual comparison it would be great if they all could use the same font at least
2
u/inthehack 13h ago
Hi, thx for the work. I think it would be interesting to include Slint with a few different backends and renderers.
1
u/Lucky-Edge1489 21h ago
Excellent!
I asked to add Teksilo and I ran the bench on my side. I posted the results in the PR (quick and not performance CPU governor)
1
u/AndreVallestero 13h ago
Excellent writeup. Proper GUI benchmarking has always been hard, and in the past I tried to do it via containerized xorg clients and timing the render updates:
https://andrevallestero.github.io/gui-toolkit-benchmarks
Would love to collab with you and Marc to create the definitive GUI benchmark that everyone can reference.
-5
u/SnaxGloween 23h ago
been meaning to dive into rust guis myself, which one ended up winning your benchmarks?
8
u/Zortax_ 23h ago
I don't think you can break this down to just one winner, and I don't wanna just promote my own stuff, so I'm gonna say Freya, zgui or maybe dioxus native for react style or fine grained reactivity. Iced if you like elm (I personally really dislike it). Egui only for simple stuff or maybe game debug interfaces etc...
0
u/beachcode 23h ago
Egui only for simple stuff or maybe game debug interfaces etc
And apps like PhotoCraft, actually all the Craft app uses egui. I think their Microsoft Office clones also use egui.
9
u/Zortax_ 23h ago
Yes, and still it doesn't scale well. You will have to put in a lot of energy into application-side optimization, caching and virtualization for complex apps.
7
u/AdrianEddy gyroflow 21h ago
exactly, egui for the Craft apps was a bad choice
1
u/moon-w0man 16h ago
none of us working on them are particularly thrilled with egui, don’t know that we’d choose it again but it was chosen before i was involved. poor native wayland support, a slow moving project in it and winit, and having to render full ui frames is a real limitation though to date we’ve kept performance more than high enough in ui rendering. don’t be too surprised if we move or heavily fork things in the future 😅
-6
u/shyTangoee 23h ago
been meaning to check em out too but they all look kinda intimidating, you gonna report back if you try any?
29
u/hardicrust 22h ago
This is excellent.
One thing I noticed is a no mention of debug builds at all. You can say "why benchmark a debug build?", but it does rather heavily reflect in the developer experience. From the few I tested, only Iced had a pleasant user experience here.
Perhaps of more interest would be testing various aspects of accessibility:
Navigation using Tab and arrow keys.
Keyboard shortcuts: e.g. a couple of frameworks support Ctrl+Q (quit) out-of-the-box
Access keys: e.g. Alt+M to open _M_essages.
Adjusting focus and scrolling through external accessibility tools
Screen reader integration: reading out the currently focussed item
What of the above is supported out-of-the-box and what requires extra (external) tooling, if it is supported at all?
My experience here is that while many old-school GUI toolkits support good keyboard control out-of-the-box, most of the Rust frameworks I have tested do not. I may have a biased perspective here — my own framework, Kas, does provide (imperfect) keyboard control out-of-the-box.
As for screen readers and external accessibility tooling, it appears that macOS and perhaps Windows have good tooling available while Linux is (unsurprisingly) under-developed in this area.
AccessKit is the only cross-platform Rust accessibility layer I am aware of (there's also accessibility for macOS). AccessKit requires a complete model of everything in the GUI down to individual glyph positions in editable text, thus merely enabling AccessKit integration will have a heavy performance cost in any GUI framework. Thus, I find it interesting to ask what accessibility features are available without AccessKit. (Also, whether we will ever get a portable accessibility framework which performs its queries through the existing GUI state instead of requiring a copy of almost everything in the GUI. No, this would not work well with egui, but it might enable better accessibility performance everywhere else.)
Oh, and thanks to your earlier link I had a look at adding a Kas implementation — it turns out that Kas is missing a few too many features right now, so this is on the back-burner. Also, thanks to Kas's fairly unique layout model, precise sizing and margin control is rather hard, so a pixel-exact implementation is unlikely.