godotengine / godot

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

Performance improvement with MSVC 2019 on Windows - 30% FPS increase in tps demo #30971

Closed rpopovici closed 2 years ago

rpopovici commented 5 years ago

Hello guys,

I want to share with you my findings about compiling with MSVC 2019 on windows: First, I want to say that msvc 2019 is much faster than previous versions at compiling and linking. Then, in the tps-demo project, I get a 20-30% FPS increase - debug build within the editor.

The only thing I did was to add these compile options to the SConstruct file: if env.msvc: env.Append(CXXFLAGS=['/std:c++17']) env.Append(CXXFLAGS=['/Ob3ity']) env.Append(CXXFLAGS=['/GF']) env.Append(CXXFLAGS=['/Gs']) env.Append(CXXFLAGS=['/Gy']) env.Append(CXXFLAGS=['/Qpar'])

Test machine was i7700H with GTX 1070. Run the project in debug mode from the editor. The average FPS before optimizations, it was aprox 65 FPS, at start location. And after, it was aprox 90FPS with max GI, no AA and no SSAO. Same setup will give +10FPS with a release build.

Can anyone explain why such a big difference.. Thanks!

rpopovici commented 5 years ago

4313

23998

Calinou commented 5 years ago

Note that official Windows binaries are compiled using MinGW with link-time optimization enabled. See also the Godot build containers.

rpopovici commented 5 years ago

@Calinou I am not using official builds. I am using custom builds made for Godot 3.2-master with msvc. The only difference is the param list above. And,of course, I have not touched the source code. It's the master branch unaltered

Calinou commented 5 years ago

@rpopovici If you have some time, could you share some performance numbers with individual flags being enabled/disabled? This way, we could narrow down the performance improvements to specific flags.

rpopovici commented 5 years ago

@Calinou It's /Ob2 or /Ob3 with msvc 2019. The other flags don't matter much. Also same setup with release build will give an extra 10FPS.

It would be nice to see how inline optimization performs on linux

Ranoller commented 5 years ago

I test that flags in msvc2019.... is not magic. It ups general fps (not much in a 2D game) in execution, but i think it´s rendering, because my plugins executes slower. A text parse in a plugin in a script of+4000 lines is performed in 3500msec without flags and 4100msecs compiling with that flags. All in editor (plugins are not in game)

piratesephiroth commented 4 years ago

Perhaps this is relevant https://github.com/plasma-umass/coz

Calinou commented 2 years ago

Closing, as this is not relevant for official Windows builds which use MinGW. Also, this would need to be tested again on the latest master branch and MSVC 2019 release, and soon MSVC 2022 (once SCons and Godot's buildsystem add support for it).

If you can find C/C++ compiler flags that result in consistently better performance, feel free to open a pull request to change the MSVC flags with target=release_debug and target=release :slightly_smiling_face: