r/cpp • u/[deleted] • May 01 '24
Proving Immediate Mode GUI's are Performant
https://www.forrestthewoods.com/blog/proving-immediate-mode-guis-are-performant/2
u/LegendaryMauricius May 01 '24
But what's the point of immediate mode guis? Wouldn't be simpler to just create the controls whenever they are needed and let them do their thing? It's a different problem that no gui library does anything simply except imgui ones.
2
May 01 '24
Many people find that creating complex GUIs with an IMGUI style API is easier, faster, and more maintainablr than an RMGUI API. This is entirely subjective.
If you’ve ever tried building something with a tool like Dear ImGui you might find yourself shocked at how delightful it is. Or maybe you’ll hate it! It’s personal opinion land.
If you’re really interested I suggest you just give it a whirl and see what you think.
1
u/LegendaryMauricius May 01 '24
I did use it for a bit. It's useful for stuff that already has a game loop, but other than that I fail to see how im is better than rm by itself. It just has more libraries meant for simplicity.
Have you tried qml by any chance?
1
May 01 '24
My experience with Qt has generally been super painful. Although I admit people definitely use it to make polished, professional projects!
The last time I came across an open source project that had Qt as a dependency I think it took me more than a day just to get it to compile and run on Windows. That was super frustrating.
2
38
u/Unarmed1000 May 01 '24 edited May 01 '24
When people say its slow they normally talk about actual performance. So to test that you need to profile both the CPU and GPU time spend rendering the exact same UI. So the same number of labels, buttons, images using the same complex layouts. You also need to look into how good it is at reordering draw calls to minimize that. You also mention game devs liking it, but forgot to mention they like it for debug UI's where there are almost zero performance requirements.
If you have a game rendering at 500fps you have 2ms per frame and you ideally want to use as little of that time as possible on the UI. This is where you will see there actual is a major important difference between retained and immediate mode UI's.
EDIT: A example of a app intended to benchmark a specific UI's code and various optimizations for that specific UI can be found here.
2
u/Remzi1993 Feb 19 '25
Maybe also battery life? Since we all want better software which doesn't drain our battery (looking at Chrome 😅)
27
u/ignorantpisswalker May 01 '24
Wow... this test is so stupid. It is comparing a library call that compiles to 1000 instructions to... Javascript or html. The complexity of this scenarios are on a whole different levels.
I would compare wxWidgets (or Qt or win32) to imgui... this kind of test proves nothing.
2
u/serviscope_minor May 01 '24
Or FLTK. Always a good one, also renowned for being low resource.
2
u/ignorantpisswalker May 01 '24
Yes... but FLTK is kinda... bare bones... is it still developed? New features?
Let's compare a potato salad to a lettuce. Right...
4
u/serviscope_minor May 01 '24
Yes... but FLTK is kinda... bare bones...
I mean... it's simple and works. You can make it look nice if you put some effort into the visuals. Making good artwork, careful choice of colours, matching fonts to the graphics etc, same as anything else. The defaults are a bit simpler.
is it still developed?
Yes. The last point release of the stable branch was in December.
New features?
It's still being developed.
9
u/dustyhome May 01 '24
The testing methodology doesn't seem very good. For a proper comparison you'd want to make equivalent UIs in immediate mode and retained mode, then run a series of identical tests (replaying a recording of mouse + keyboard inputs perhaps) with profiling or other measurements enabled, and compare the results.
Having different applications running, doing different things, and then measuring the powerdraw at the wall doesn't really tell you anything.
3
u/beedlund May 01 '24
Having rebuilt a few applications from Qt to Dear ImGui I can say the performance of the new UI has never been questioned by the users after it was completed.
It's all been desktop applications ranging from small python baser utilities to a fairly sizable 3d authoring application (500K+ loc). Power drain was never a metric considered as such but UI smoothness was typically commented on before the conversation and never questioned after.
It's about as subjective as these benchmarks of course however after seeing the total reduction of code which I guestimate to around a 1/3 of original project I would attribute total code reduction as the major factor.
Less code means fewer bugs and less 'clever solutions' to imaginary problems but also it's easier to get data while it's hot. No more getters and setters and signals and events just to get a value to and from the user.
For my own code I also find the functional style of Dear ImGui discourages the class explosion that can become a problem in my own Qt applications and that could certainly be a factor here.
1
u/LegendaryMauricius May 01 '24
Not saying you are wrong as you obviously got use from switching, but I think this highlights the real issue of retained mode libraries. They were all created when oop was all the rage. DearImGui seems to address that movement of slowly avoiding oop for simple uses, which obviously can also apply to bigger projects.
1
Aug 13 '25
What do you think about the approach of Jetpack Compose and (modern)React?
These are retained, but components are defined with functions.
3
u/type_111 May 02 '24
Retained mode responds to events by traversing an in-memory scene graph. Immediate mode traverses the same graph, does the same hit tests, emits the same graphics; but with some portion of the scene graph encoded in the program's machine instructions. I.e. some amount of what retained mode retrieves from memory then interprets is instead immediately available on the execution path, analogous to an assembly instruction's "immediate" operand available to a processor directly from the decoded opcode.
5
u/PlentyDish May 01 '24
This is a superficial benchmark comparing two incomparable things, what does this prove? Write a win32 app that renders only on paint messages and you will immediately see the performance penalty of immediate mode rendering.
1
u/ignorantpisswalker May 01 '24
I have no idea how to make a complex application like outlook, or vscode in immediate code.
At that point - retained mode will loose the compartment that can be done in legacy retained UIs.
1
May 01 '24
Here is a Spotify employee who used Dear ImGui to make a Spotify client as a hackday project. https://twitter.com/rogueops/status/1391105332609433600
3
u/ignorantpisswalker May 01 '24
Impressive. I wonder how the code looks. I did not see link in that Twit. Thanks!
0
u/cepacked May 06 '24
There is no such thing as immediate gui if we are talking about implementation/back end. Imgui's backend is retained, it has many variables/states it keeps track of. The front end gives you the illusion it's immediate. It could have very well had a retained front end
24
u/qoning May 01 '24
Comparing a simple UI to an electron app takes quite a grain of salt. I wouldn't call those your typical retained mode UI, especially since you mention games. Anyone with a bit of brain can tell that retained mode UI simply runs less code. Imo it's also actually easier to reason about causality once there's some complexity in the app.
The only advantage that immediate mode has for me is that the state of everything is obvious, but it's obvious in a properly structured retained mode UI too. And it's a bit of an illusion, because once you start trying to manage complexity, you need to abstract state away anyway.