You are also often comparing imgui/egui - a library, to retained mode - a concept.
> in an imgui [...] adding more widgets or more frequent updates have a negligible performance impact
Absolute nonsense.
> Retained mode [...] hope that the system is flexible enough to support what you want, whereas with an imgui you can just directly draw and shade geometry
At least in browsers you can just use <canvas /> if you need to do that. If you're implementing retained mode in a custom application - well it also must have some way to draw things on the screen.
I used Egui as an example because that's relevant to the shared article. When I say "imgui" I am talking about the paradigm, not Dear Imgui.
In manu retained mode UI systems you can break out of the paradigm with a Canvas element, but that is quite different from an imgui - it's akin to using a 2d drawing API like Skia.
> Absolute nonsense.
How so?
The point I'm making is a subtle one. I do think you can go very far with an immediate mode GUI paradigm, and it's also certainly the case that most of the imguis you see are performant. But I still wouldn't choose it for a design or productivity app.
Once you do all the caching of text layouts and building of intermediate trees for a11y, you no longer have a pure imgui, but rather a hybrid.
I'm going to try to get this point across in an analogy, apologies to people not familiar with the referent.
Let's say you're frustrated with the size and complexity of a modern C compiler like clang or gcc, and want to do something simpler. One of the design decisions is whether use SSA (static single assignment) as the basis for the intermediate representation. If you're going for simplicity, you might quite reasonably choose to skip it; you can generate reasonably good code straight from the AST.
But then, you and your users get dissatisfied with merely reasonably good code, and want some of those optimizations that make production compilers generate actually fast code – constant folding, common subexpression elimination, strength reduction, etc. You can certainly implement them as AST transforms, but it gets difficult to track everything? You add a bunch of logic and eventually get those optimizations to work about as well as the SSA-based version in real compilers.
Another compiler designer has similar goals but uses a different strategy: dive in and do SSA from the beginning, which is not as simple at first, but then you can just do those optimizations "from the book," without a lot of friction.
Basically what I'm saying is that I prefer the second compiler. It's not to say the first can't be made to work.
If I understand the point of the analogy, it's basically that when you bolt sophisticated optimizations onto a representation that wasn't designed for them, the bookkeeping accumulates in an ad hoc way, while a representation purpose built for those transforms makes the same optimisations feel like they fall out of the structure. Would that be valid?
If so I would actually swap imgui's and retained mode ui's around. In an imgui, you can implement domain-specific caching and other performance optimisations for your bottlenecks, whereas in retained mode UI you're building against a general system and you often need to resort to hacks to rescue performance, or design your data model in a way that is amenable to change detection. Memoization, keys and identity gymnastics, state sliced into atoms/signals/items, "this component only depends on X" annotations, Equatable conformances, Identifiable fake IDs, keeping structs small and pruned so the diff is cheap, splitting views so diff granularity lines up with actual change granularity, id resets to force identity, etc. Fixing performance in React is largely about reshaping your data model until it's legible to the framework's change detection. When you use fine-grained reactive systems you need to adopt the framework's data stores and it ends up infecting your entire application. You cannot just pull in a dependency and use it's state directly - you need to martial it into signals or stores or set up subscribers.
Whereas in an imgui it's trivial to benchmark and if you notice that a list is performing a lot of work on each update cycle you can apply an optimisation that is impossible in a more general system.
Fwiw I'm building a desktop application with Egui and Bevy and it's been a breath of fresh air compared to building applications with classical retained-mode systems. An entire class of bugs and complexity regarding state management just goes away. Performance is ~3ms including the entire render pass (more than just UI), and all of the complex components that required caching and other performance optimisations would have had to be hand-rolled in a retained-mode system anyways - except with Egui those optimisations are simple to build. All of the state just lives in Bevy's ECS without any real considerations for the UI, because the UI systems can just reach into the world and read it directly.
But to each their own - some people seem to "click" more with a retained mode approach and it's still a valid choice to use it if you prefer it.
Immediate
Dear ImGui 7.5
ImPlot 8.9
EGUI 8.2
Rerun 11.1
Retained
Spotify 5.8
VSCode 7.0
YouTube 11.5
Facebook 8.7
https://www.forrestthewoods.com/blog/proving-immediate-mode-...This is a necessity if you want to support elements that adjust their size based on contents and parent constraints. It's not something specific to retained mode. Immediate mode would also need multi-pass layout to do the same.
I do want to nitpick this part however:
> That’s been playing out architecturally in the choice between immediate mode and retained mode. 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. To be considered really production-ready, it has to establish stable widget identities to build and update the accessibility tree, and it has to reliably cache expensive intermediate artifacts such as text layouts (simple immediate mode often gets around this by cutting corners in text layout, which may be 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.
It's a common criticism but I don't think it's based on anything other than preconceived notions about rendering being slow and doing a ton of caching makes everything faster. but neither seem to be backed up by any sort of empirical evidence. Anecdotally every imgui I've used has been lightening fast, and retained mode UI's like the browser, windows software, new Macos apps written in SwiftUI, etc, have performance problems.
Egui has solved the accessibility problem and does a lot of caching: galleys, glyphs, and layouts are cached, packed texture atlases minimize GPU uploads, and it uses inputs & animation state to draw on demand.
I also don't see how retained mode UI would scale better. Retained mode UI's are typically slow - they have a complex multi-pass general layout system and a ton of bookkeeping, which is why you typically need to keep updates to a minimum and ever-more-complex change tracking systems are being built to reduce updates to a minimum. This doesn't scream scalability to me - whereas in an imgui there is a baseline overhead but adding more widgets or more frequent updates have a negligible performance impact. the worst case for retained mode is a UI which has many widgets frequently updating multiple times a second, which means you approach the update and drawing of imgui but with the additional overhead of the change tracking, bookkeeping, etc of the retained system.
Also there is nothing fundamental about imgui layout systems being limited, and in my experience it's not that difficult to build custom widgets to implement pretty much anything. Retained mode layout systems are usually declarative, where you describe a layout and hope that the system is flexible enough to support what you want, whereas with an imgui you can just directly draw and shade geometry to get whatever you want.
Otherwise, great article and I look forward to the future of Rust UI.