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

Large number of CanvasItems in the scene slow down input #56199

Open
TrickMe opened this issue Dec 23, 2021 · 8 comments
Open

Large number of CanvasItems in the scene slow down input #56199

TrickMe opened this issue Dec 23, 2021 · 8 comments

Comments

@TrickMe
Copy link

TrickMe commented Dec 23, 2021

Godot version

3.4.2 stable official

System information

Linux Mint 20.2 Cinnamon, Kernel 5.11, GLES3, AMD Athlon II X4, AMD Radeon Rx 570X, Mesa 21.3

Issue description

Mouse movement cripples performance massively if many (~10.000) CanvasItems (Control or Node2D) are in the scene.
It's specially bad if Input.set_use_accumulated_input() is false, but is also noticeable if true.

Steps to reproduce

Place many CanvasItems in the scene, about 10.000 and move the mouse around.

Minimal reproduction project

rep_manyLines.zip

@HubbleCommand
Copy link

Win10 4th gen intel i7, so slightly better than @TrickMe.

Just did a simple test where I spawned 10k sprites & 10k buttons. No input lag.

For fun I made it spawn 50k of each. The mouse was fine, but there was a slight delay in the "pressed" signals from the buttons.

@TrickMe
Copy link
Author

TrickMe commented Dec 27, 2021

@HubbleCommand
A project of mine is also not effected by this issue, although it uses thousands of sprites.
Have you checked with my minimum reproduction project?
Does spawning even more sprites have any effect?

@HubbleCommand
Copy link

I will look at the project later if I have time.

There are 2 solutions if you have that many sprites that are affecting performance:

If not all sprites are on the screen, and you have large / high detail sprites, you can convert them to 2D meshes.
If pretty much (preferably all) sprites are on the screen, you can use MultiMesh2D.

While multimesh2D uses 2D meshes, you use them in opposite scenarios:

  • Mesh2D splits a sprite into parts, and will only draw the parts that are on the screen
  • MultiMesh2D will always draw all of the sprites and all their parts (if it works like the 3D version), but reduces memory as they all use the same resource

@ConteZero
Copy link
Contributor

I can confirm the issue, tested on Linux with an Intel i5 11500, here some results:
I get 1 fps when moving the mouse with 100.000 Node2D
I get 1 fps when moving the mouse with 50.000 PanelContainers
I get 1 fps when moving the mouse with 15.000 PanelContainers with a Label child

@Calinou
Copy link
Member

Calinou commented May 23, 2022

I'd look into using a C++ profiler to determine where the bottleneck is.

That said, asking the engine to perform 15,000+ input events every time the mouse cursor is moved is asking a lot. It'd probably be better to throttle the frequency at which InputEventMouseMotions are sent if the input system is overloaded.

@ConteZero
Copy link
Contributor

For the PanelContainer test I've added the nodes as a child of a VBoxContainer so only a couple of them are visible on screen (18 out of 15.000 are visible).
Probably limiting the mouse motion check to just the nodes on the screen would help in this case.

@ConteZero
Copy link
Contributor

I've also tried to use MOUSE_FILTER_IGNORE but it doesn't solve the issue.
It could be useful to have a real "ignore" mouse filter that will ignore the event (as if the control was hidden):
godotengine/godot-proposals#3613

@ConteZero
Copy link
Contributor

I've done the same test with a low spec pc (Intel Celeron J3355):
I get 1 fps when moving the mouse with 10.000 Node2D
I get 1 fps when moving the mouse with 6.000 PanelContainers
I get 1 fps when moving the mouse with 4.000 PanelContainers with a Label child

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

No branches or pull requests

4 participants