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-...
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.