Just toggling this progress bar seems to add an additional 6ms and involve a surprising amount of UIR.ImmediateRenderer and gc?.. I even tried setting the usage hint (although I guess this should be set on the moving element within the progress bar anyway):
Is there anything obviously wrong I might be doing here or is it simply that the progress bar is using some old very inefficient code?
I guess I could add a resizing element or custom updating mesh instead but it would be nice if doing this wasnât brutal
Many thanks in advance for any help or pointers where I might be going wrong.
ProgressBar isnât implemented with ImmediateRenderers (which by the way means that rendering isnât performed by UIT but rather with GL or IMGUI), so youâre probably capturing other stuff in the profiler.
Regarding the usage hints, they must be used cautiously. Donât set the DynamicTransform usage hint unless the transform of the element is actually being modified frequently. Otherwise youâll degrade performance.
I tested your code and what you see is the cost of rendering the whole inspector, and unfortunately most of it is not UIToolkit yet so itâs much slower. So when you modify the progress bar, you force the whole inspector window to repaint, and that includes IMGUI code of other components. If you hover quickly over many items of the inspector, you will observe a similar slowness in the profiler. As time passes, more and more components will use UIToolkit and this should help in that regard.
Regarding DynamicTransform, when the progress bar is updated, its transform isnât modified so itâs not a good use case. Only the width of the inner progress element is modified, which is different from the transform (not a scaling).
Thanks for taking a look. The width adjustment not being the same as scale makes a lot of sense. Does that mean no matter how I update something in the inspector (i.e. using VisualElements instead) that cost will be there until UIT is the default for inspectors? I currently donât use any non-UIT elements and I have to run QueuePlayerLoopUpdate for updating the scene view etc. If so, any update / rough eta possible on when that default might be coming?
Thanks again.
Custom inspectors will remain rendered with IMGUI until their owners convert them to UIT. There is no ETA at the moment. Default inspectors will use UI Toolkit most likely sometime next year.
Apologies - last clarification I hope. âCustom inspectors will remain rendered with IMGUI until their owners convert themâ - who are the owners in this context? Am I not the owner of the above example custom inspector? Or are you referring to the team that owns the concept of custom inspectors?
Just wanting to be sure I havenât missed some simple concept like I should be extending from something other than Editor?
If I replaced all contents of the editor with components that didnât use gl/imgui would this help? In which case is there a way to find out which are safe âpure UITâ components?
Thanks for your continued help.
There are multiples team inside unity with their own area of expertise, hence owner. Because of this, each team handle the switch form IMGUI to UITK at their own pace. Each small change will reduce the overall cost of a redraw as we can cache a lot of information in UITK.
Just an idea: In your application, can you reduce the frequency at which you update the progress bar? A Lot of application can have a progress bar refreshed twice per second. This would reduce the overhead.
Thanks @SimonDufour - I can certainly reduce the update frequency but hopefully this gif illustrates the responsive ux Iâm striving for. If this really is costing up to 6ms in practice as it seems to be and thereâs nothing I can do about it, I likely will have to reduce update, remove the feature or explore some more hacky ideas (floating editor window?) so any other ideas are welcome.
I see how you want the progress bar to match the input of the user! It is definitely different from a progress bar used to indicate a long operationâs progress.
To keep latency to a minimum, I think you should let your code as is when the user moves the mouse: it will render as fast as possible up to the maximum framerate that the computer will allow. As long as you keep 60fps, Only people on a laptop (like me) will notice because of the fan noise. And with 6ms you are closer to 160fps.
By doing that, the performance will naturally increase with the next version of unity.
Do keep in mind that the profiler does reduce the performance a little, especially in deep profile (I have seen up to 40%). So test the look and feel without it also as it is more representative on what your user will do.
Thanks Simon. No need for me to be using a progress bar - just convenient. I could easily replace this with a couple of VisualElements though my understanding is that the cost would be effectively the same regardless.
To be clear the 6ms is âextraâ just from the progress bar and does not include the timeline, scene & game views updating so Iâm actually closer to 30fps. Thatâs why itâs frustrating. I havenât had a chance to test this yet but is the issue that one component redrawing within an inspector tab dirties the entire tab and hence redraws all the other components and inspectors? (that would explain the difference between my minimal repro and realistic numbers)
Edit: On re-reading I realise that is indeed what Alexandre was saying: ââŚyou force the whole inspector window to repaint, and that includes IMGUI code of other componentsâ