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

NavigationAgent: drastic drop in framerate when adding Node NavigationAgent #56838

Closed
thoced opened this issue Jan 16, 2022 · 17 comments · Fixed by #60359
Closed

NavigationAgent: drastic drop in framerate when adding Node NavigationAgent #56838

thoced opened this issue Jan 16, 2022 · 17 comments · Fixed by #60359

Comments

@thoced
Copy link

thoced commented Jan 16, 2022

Godot version

3.5 beta 01

System information

Windows 10, GLES3, NVIDIA

Issue description

When adding the Node NavigationAgent, the framerate drops drastically for no reason. I publish a small scene for the tests. The NavigationAgent, according to the documentation, must be one of the child nodes of the Navigation node. To carry out the test, two tests must be carried out. One using the NavigationAgent and the second test by deleting it in the tree.

The VSYNC is set to FALSE to better observe the difference

Steps to reproduce

  • Test with NavigationAgent and see the FPS
  • Test without NavigationAgent (delete node) and see th FPS

Minimal reproduction project

NavigationAgentTest.zip

@rpgray
Copy link

rpgray commented Jan 16, 2022

Just wanted to say I have been waiting for you to open this issue since you posted the previous one. :)
I'm experiencing similar troubles with NavigationAgent2D. Simply having it in my scene attached to a KinematicBody2D, even without any pathfinding code running, it drops my fps from a stable 60 to around 45 (rising and dipping constantly) and causes all movement to jitter and stutter.
This includes a different KinematicBody2D that is using the old GetSimplePath() workflow, which works just fine once the NavigationAgent node is deleted.

Ps: This is all using 2D components in Godot Mono, in case that matters.

@thoced
Copy link
Author

thoced commented Jan 16, 2022

Yes indeed, I have the same problem. Even without path search, without NavigationMeshInstance placed, simply with the NavigationAgent node in the scene and it's the FPS that drops directly

@tomkun
Copy link

tomkun commented Jan 17, 2022

Can confirm, process frame time jumps to ~70ms in vanilla 3.5.beta.1 on x64 Win
In my use case Agent is not part of the Navigation subtree, and the performance drop happens specifically on set_navigation() call.

@akien-mga akien-mga modified the milestones: 4.0, 3.5 Jan 17, 2022
@Scony
Copy link
Contributor

Scony commented Jan 17, 2022

Cannot repro on 3.x on bef2e3d on x86_64 manjaro linux

@Brandon-M-Hartman
Copy link

Also confirming - same issue in everything I try. My own games, demo games, repros, all of it.

@akien-mga
Copy link
Member

I can't reproduce the issue either on Linux with the reproduction project in #56838 (comment), neither with 3.5 beta 1 nor 3.x (e17af68).

I have a stable 1420 FPS with or without the NavigaationAgent node in the scene.

@mhilbrunner
Copy link
Member

I can reproduce it on Windows 10/NVIDIA. Without I have a stable 2700-2800 FPS without any large fluctuations, with the node its constantly changing between 1200-1900 FPS.

@YuriSizov
Copy link
Contributor

Can't reproduce on Windows 10 with AMD Radeon 5700 XT. Stays around 3k FPS with or without the NavigationAgent node. However, what does kill FPS for me is moving the mouse. Just waving the cursor inside of the window takes around 1k FPS. That's likely unrelated, but very curious.

@trollodel
Copy link
Contributor

trollodel commented Jan 28, 2022

Something similar was already reported for master: #50448

@lawnjelly
Copy link
Member

lawnjelly commented Jan 28, 2022

On Linux Mint 20, latest 3.x with a 120x120 window I get:
Without the node: 3600 fps
With the node: 2900 fps

Reason for the small window, with a big window you are just testing your fill rate (and mine is low with integrated GPU).

One possible is reading back info from the navigation server, this could be stalling, maybe on some OS more than others.

These drops to 1000 or more are perfectly reasonable for a bit of CPU load. The OP didn't describe what figures they get with the MRP.

@tomkun
Copy link

tomkun commented Jan 29, 2022

I've tested the 2D version on Ubuntu 21.10 as well and couldn't reproduce the issue.
On my windows machine, however, the problem has 100% repro rate.
Tested on 3.5 beta1 b9b23d2 on both systems.

image

Minimal repro: 3.5-beta1_nav.zip

@Nukiloco
Copy link

I'm actually currently having this issue with NavigationAgent nodes. Just placing one down cause the FPS to tank a lot though the amount NavigationAgent nodes does not take the FPS further which is strange?

Can't reproduce on Windows 10 with AMD Radeon 5700 XT. Stays around 3k FPS with or without the NavigationAgent node. However, what does kill FPS for me is moving the mouse. Just waving the cursor inside of the window takes around 1k FPS. That's likely unrelated, but very curious.

Moving around the mouse also causes the FPS to drop even further which is seriously strange.

I'm currently using Windows as well.

@GameDevLlama
Copy link
Contributor

It also took me quite some time tracking the issue down, since the lag spikes happen on the idle frame (at least for me).
I thought it might be interesting to see the profiler just for consideration:

image

@Calinou
Copy link
Member

Calinou commented Feb 12, 2022

It also took me quite some time tracking the issue down, since the lag spikes happen on the idle frame (at least for me).

Adding profiler support for NavigationServer would be interesting, but it should be done in master first.

@Defaultsound
Copy link

Defaultsound commented Mar 17, 2022

I've also come across this issue in Alpha 4. It also seems increasing the "Physics Tick Per Second" also will affect the rate at which the framerate will tank. Even with no logic on the NavigationAgent3D, over time the Physics process will go up and up in ms.

@macryc
Copy link

macryc commented Apr 9, 2022

Just raised this under Godot 4.0 alpha 6. Same issue but it's not tracked under 4.0 milestone.

@Calinou Calinou modified the milestones: 3.5, 4.0 Apr 9, 2022
@lethiandev
Copy link
Contributor

lethiandev commented Apr 12, 2022

I did some investigation and it might be an issue with thread_process_array on Windows. I've replaced some code in NavMap::step method to update the maps in single threaded manner.

void NavMap::step(real_t p_deltatime) {
	deltatime = p_deltatime;
	if (controlled_agents.size() > 0) {
		for (size_t i(0); i < controlled_agents.size(); i++) {
			controlled_agents[i]->get_agent()->computeNeighbors(&rvo);
			controlled_agents[i]->get_agent()->computeNewVelocity(deltatime);
		}
		// thread_process_array(
		// 		controlled_agents.size(),
		// 		this,
		// 		&NavMap::compute_single_step,
		// 		controlled_agents.data());
	}
}

With this simple change NavigationAgent no longer stutters my project. Also I've noticed that the problem with thread_process_array is less noticeable with disabled vsync on my setup.

Replaced thread_process_array with "single threaded mode" and vsync off -
image

Using thread_process_array with vsync off (notice the spikes on beginning only) -
image

Using thread_process_array with vsync on -
image

Edit: Could it be possible to use thread pool with semaphores to wait for input data? Instead of creating threads every time this method is called. I'm not an expert in multithreading though, maybe someone would know better?

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

Successfully merging a pull request may close this issue.