godot
godot copied to clipboard
Debug CanvasItem redraw
I wanted to add this tool for years and always forget. This command line option:
$ godot.exe -e --debug-canvas-item-redraw
Allows to see when a canvas item is redrawn. This helps find out if something in the UI is refreshing in a way it should not. Examples as such:
- Signals causing more of the UI to redraw.
- Container resizing causes more UI elements to redraw.
- Something using a timer is redrawing all time time, which can go unnoticed.
To my surprise, the editor UI is redrawing very efficiently. There is some weird stuff with the scene tabs, redrawing when the inspector changes but most things for the most part are fine.
How it looks:
This can be enabled also from the Editor UI to debug canvas item redraws in the running game:
I suggest exposing this in the Debug menu at the top of the editor, so that projects can use this more easily :slightly_smiling_face:
@Calinou oh, that's a very good point.
Would be awesome for editor plugins and tool scripts
@Calinou done
Honestly, I would name it differently. "Debug CanvasItem redraw" makes it sound like it is going to highlight each time the CanvasItem is drawn to the screen. When in fact, it is showing when the CanvasItem is recalculating it's properties on the CPU-side. Regardless of whether the CanvasItem recalculates it's properties, it is drawn to the screen.
@clayjohn No idea, should I call it Debug GUI/2D Node Redraw ? I have no idea what might be better.
@clayjohn No idea, should I call it Debug GUI/2D Node Redraw ? I have no idea what might be better.
Perhaps. That is slightly better.
I guess the real problem is that this type of update is called "redraw" internally. But "redraw" really just means "re-record" commands. Drawing happens every single frame regardless of whether the CanvasItem is "redrawn"
To me it's fairly established in Godot lingo that "redraw" indeed means "run the update()
method to recompute what should be drawn", and that's the expensive part that needs to be minimized (i.e. "redrawing too often is bad for performance").
This does not work well with update spinner, it's constantly redrawing:
https://github.com/godotengine/godot/assets/2223172/b0134649-c4a4-4399-a51f-b1c3b083de04
Using --debug-canvas-item-redraw
should probably force-disable it.
There is some weird stuff with the scene tabs, redrawing when the inspector changes
That's because unsaved status is being updated. Maybe it could be skipped if the tab is already marked.
EDIT: I found something weird. The editor is getting redrawn when moving mouse cursor outside the window (seems like some recent regression). It's evident by the update spinner moving, however the redraw debug does not highlight it.
EDIT2:
Found it. It's caused by an addon. Although it's weird. Are docks supposed to redraw when inactive (invisible)? In this case it was a Label updating text inside _process()
.
Rebased to solve merge conflict, and added the warning suggested by @clayjohn.
Thanks!