Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug CanvasItem redraw #79169

Merged
merged 1 commit into from
Oct 11, 2023
Merged

Conversation

reduz
Copy link
Member

@reduz reduz commented Jul 7, 2023

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

@Calinou
Copy link
Member

Calinou commented Jul 7, 2023

I suggest exposing this in the Debug menu at the top of the editor, so that projects can use this more easily 🙂

@reduz
Copy link
Member Author

reduz commented Jul 7, 2023

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

@Zireael07
Copy link
Contributor

Would be awesome for editor plugins and tool scripts

@reduz reduz force-pushed the debug-canvas-item-redraw branch from 057ffd9 to 0043be5 Compare July 8, 2023 13:06
@reduz
Copy link
Member Author

reduz commented Jul 8, 2023

@Calinou done

@reduz reduz force-pushed the debug-canvas-item-redraw branch from 0043be5 to e824034 Compare July 8, 2023 15:05
@reduz reduz requested a review from a team as a code owner July 8, 2023 15:05
@clayjohn
Copy link
Member

clayjohn commented Jul 8, 2023

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.

main/main.cpp Outdated Show resolved Hide resolved
@reduz
Copy link
Member Author

reduz commented Jul 10, 2023

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

@clayjohn
Copy link
Member

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

@akien-mga
Copy link
Member

akien-mga commented Jul 10, 2023

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

@reduz reduz force-pushed the debug-canvas-item-redraw branch from e824034 to e4f3241 Compare July 26, 2023 10:46
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected.

@KoBeWi
Copy link
Member

KoBeWi commented Aug 12, 2023

This does not work well with update spinner, it's constantly redrawing:

godot.windows.editor.dev.x86_64_givobFwGkS.mp4

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

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.
@akien-mga akien-mga force-pushed the debug-canvas-item-redraw branch from e4f3241 to 407b16a Compare August 28, 2023 10:54
@akien-mga
Copy link
Member

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

@akien-mga akien-mga requested a review from clayjohn August 28, 2023 10:54
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Testing locally it appears to work well.

@akien-mga akien-mga merged commit 4b7cc99 into godotengine:master Oct 11, 2023
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

9 participants