godot icon indicating copy to clipboard operation
godot copied to clipboard

Debug CanvasItem redraw

Open reduz opened this issue 1 year ago • 8 comments

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:

debug-scene-redraw

This can be enabled also from the Editor UI to debug canvas item redraws in the running game:

image

reduz avatar Jul 07 '23 17:07 reduz

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 avatar Jul 07 '23 17:07 Calinou

@Calinou oh, that's a very good point.

reduz avatar Jul 07 '23 18:07 reduz

Would be awesome for editor plugins and tool scripts

Zireael07 avatar Jul 08 '23 09:07 Zireael07

@Calinou done

reduz avatar Jul 08 '23 13:07 reduz

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 avatar Jul 08 '23 22:07 clayjohn

@clayjohn No idea, should I call it Debug GUI/2D Node Redraw ? I have no idea what might be better.

reduz avatar Jul 10 '23 10:07 reduz

@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"

clayjohn avatar Jul 10 '23 10:07 clayjohn

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

akien-mga avatar Jul 10 '23 10:07 akien-mga

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

KoBeWi avatar Aug 12 '23 15:08 KoBeWi

Rebased to solve merge conflict, and added the warning suggested by @clayjohn.

akien-mga avatar Aug 28 '23 10:08 akien-mga

Thanks!

akien-mga avatar Oct 11 '23 06:10 akien-mga