godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
88.73k stars 20.12k forks source link

Performance regression since 4.2-beta1 when calling `TranslationServer.set_locale()` every frame #85718

Closed Loneliiii closed 9 months ago

Loneliiii commented 9 months ago

Godot version

4.2

System information

Windows 11

Issue description

I started a project in Godot 4 and updated Godot and ended up with Godot 4.2dev_6 because this was compatible with the modi_player addon and Glow at the same time. Other Versions either had framrate issues (like the main problem i have now) or the addon not working.

After Godot 4.2 stable came out, I tried to work in my game with this Version and get massive framerate issues (5fps) in the forward+ and mobile renderer, even in an empty scene. I tried turning off hdr / glow and changed other project settings, but nothing works. When I change to the Compatibility render I get the maximum amount of frames possible.

I have a Asus Rog Flow X13, Ryzen 7, GTX 1650 with Max-Q Design and a AMD Radeon Graphics

Steps to reproduce

its only in this project, no else, but here are the stept I did with the Game.

Minimal reproduction project

I won't upload my game here, because I'm pretty far in developement.

clayjohn commented 9 months ago

Can you work on creating a minimal reproduction project? Without one we can't really do anything to help.

The issue is likely some combination of your system, your add on, and your project. Without having access to those things, contributors can't even help you debug.

If you can't create an MRP, then you should at least try to identify what is causing the slowdown using a profiler. You should be able to identify if the issue comes from Godot, from your scripts, or from the add on you are using.

Loneliiii commented 9 months ago

I just tried it without the addon. Nothing changes. I'm gonna strip down the game to the minimum. to see, where and upload it here. Will take a bit

Loneliiii commented 9 months ago

I can't upload it here, because its too big 199MB, I stripped the game down, deleted all objects, most of the sprites/fonts and nothing changes. In the version I just uploaded I created a scene with a framecounter and a path with a sprite following it.

I also tried to open it on my Asus ROG Ally in Godot 4.2 but I get the same issue

I hope its okay, when I send the Google Drive link. https://drive.google.com/file/d/187y1EATuBMvr7RcKAHX1k9FEcgF-uZLp/view?usp=sharing

clayjohn commented 9 months ago

I ran the "test_room" scene in your project. It runs at 60 FPS on my device (11th Gen Intel® Core™ i7-1165G7 @ 2.80GHz × 8 usingintel integrated graphics). Turning of Vsync and it runs at around 900 FPS. I am using 4.2 stable. Switching to the compatibility renderer I get about 1330 FPS.

Have you been able to reproduce the issue on any other hardware? This issue might be specific to your hardware / drivers.

When you run your project, does it say that it is running with your NVidia GPU? Or does it say it is using the CPU instead? I'm wondering if there is a switchable graphics issue going on here.

Also, have you checked to make sure you are using up-to-date GPU drivers?

Loneliiii commented 9 months ago

I ran the "test_room" scene in your project. It runs at 60 FPS on my device (11th Gen Intel® Core™ i7-1165G7 @ 2.80GHz × 8 usingintel integrated graphics). Turning of Vsync and it runs at around 900 FPS. I am using 4.2 stable. Switching to the compatibility renderer I get about 1330 FPS.

Have you been able to reproduce the issue on any other hardware? This issue might be specific to your hardware / drivers.

When you run your project, does it say that it is running with your NVidia GPU? Or does it say it is using the CPU instead? I'm wondering if there is a switchable graphics issue going on here.

Also, have you checked to make sure you are using up-to-date GPU drivers?

I tried it on two separate devices. My Asus ROG Flow X13 and the Asus ROG Ally. I noticed, when I use the version that is working (in 4.2dev_6), the GPU is around 35%. The not working version (4.2 stable) at around 15%. I'm pretty sure, that the drivers are up to date. I just updated them a few days ago.

I'm currently out of ideas why this happens :/

Thank you for looking into it :)

Things I tried:

To your question, it is saying the GPU in the output when starting the game.

It wasn't possible to reproduce it with new projects, but when I copy the game files to another windows 12 PC, I get the same issue

saierXP commented 9 months ago

TranslationServer.set_locale has no performance issues in 4.2.dev6, but has performance issues in 4.2.beta1.

Godot_v4 2-beta3_win64_stYEyCvqor

System Details

Godot v4.2.dev6 - Windows 10.0.19045 - Vulkan (Forward+) - integrated AMD Radeon(TM) Vega 8 Graphics (Advanced Micro Devices, Inc.; 31.0.14057.5006) - AMD Ryzen 5 2500U with Radeon Vega Mobile Gfx (8 Threads)

akien-mga commented 9 months ago

What locale(s) are you using for your OS, and for Godot?

Loneliiii commented 9 months ago

You are a haero saierXP. I removed in a test version all of the translation stuff and it works without issues even in forward+. I remove it from the autoload physics_process and only let the translation change once when starting the game and changing the language. No problem this way so far.

My OS is currently just German and my Godot is also in German currently. The translation of the game is changed in the options menu between german and english currently.

First of, thank you guys for helping me with this! :D And maybe hopefully the "problem" can be fixed, so others don't have these performance issues. (And/Or I was just stupid by always loading the set_locale in the physics process)

akien-mga commented 9 months ago

I can't reproduce the performance issue on Linux, so this might be specific to Windows. CC @bruvzg

I don't spot right away in the 4.2-beta1 changelog what could cause that performance regression. https://godotengine.github.io/godot-interactive-changelog/#4.2-beta1

Maybe #80409 if changing the locale forces recalculating the title bar size. If so this might already be mitigated by #85542.

bruvzg commented 9 months ago

Setting locale trigger reload of all remapped resources (which was broken before 4.2) and complete reprocessing of all text, this is definitely not a fast thing and should not be done every frame.

akien-mga commented 9 months ago

Yeah I first thought about my fix to translation remapping #84791, but it was merged in 4.2-beta6, so the timeline doesn't check out with this perceived regression.

I fully agree that resetting locale every frame should not be done, but it would be good to identify why it became much more expensive than it used to be.

bruvzg commented 9 months ago

I can't reproduce the issue on macOS, but I guess we can add the check if locale is changed and only call updates if necessary.

bruvzg commented 9 months ago
Screenshot 2023-12-05 at 16 20 33

It is triggering title update, so might be related to https://github.com/godotengine/godot/pull/80409

I will check it on Windows tomorrow.

saierXP commented 9 months ago

It's very strange, I can't reproduce the previous test results and my computer hasn't been restarted. Loneliiii can you still reproduce it? Operate set_localon every frame.

Loneliiii commented 9 months ago

It's very strange, I can't reproduce the previous test results and my computer hasn't been restarted. Loneliiii can you still reproduce it? Operate set_localon every frame.

I will try it later, when I'm back home. Empty project in 4.2, renderer forward+ and then autoload a script and calling the set_local in the physics_procesd. That should be all I guess

As a question. You guys say, it is triggering the title update. Do you mean with title the game window title?

Loneliiii commented 9 months ago

I tried to replicate it on my ROG Ally (Win 11). i can replicate it, by just the steps mentioned before. here is the project, where I reproduced it locale_reproduced.zip

saierXP commented 9 months ago

Godot_v4 2-stable_win64_ft3RkQgCXi After several attempts today, I was able to reproduce the bug in forward+ and found that the System's hard disk write is 0.3Mb-0.5Mb, GPU usage is 50%, as well as cpu usage is high, GPU engine shows it is GPU-copy. after commenting out set_locale, System's usage dropped. It may be related to vulkan, after switching renderer several times, compatibility mode is normal. Mobile has higher framerate than forward+. I will do git bisect later.

saierXP commented 9 months ago

It is triggering title update, so might be related to #80409

72e2e4705942dd01d4befea3380df5d0fe77c363 is the first bad commit

akien-mga commented 9 months ago

As I mentioned yesterday, this might have been mitigated by https://github.com/godotengine/godot/pull/85542 already. Could you test latest master?

saierXP commented 9 months ago

It didn't fix it. The runtime doesn't go to the window_id ! = DisplayServer::INVALID_WINDOW_ID if branch.

Edit: Execute set_locale in _process, frame rate is 54 fps, and small fluctuation change. 35 fps in _physics_process with large fluctuations.