vi3itor / GameplayFootball

Football game
Apache License 2.0
91 stars 24 forks source link

Add O2 and LTCG flag for MSVC Windows branch #2

Closed VOM7HC closed 3 years ago

VOM7HC commented 3 years ago

CMakeList current just optimize for Unix. Clang and GNU GCC have O3 flag for optimize performance code. MSVC doesn't have O3, so I use O2 flag for speed and LTCG for force compiler use inline function every time. In my personal test, I saw in task manager, use O2 and LTCG help to improve estimate 2% ~ 5% CPU usage.

LTCG flag O2 flag

vi3itor commented 3 years ago

Hi @WesleyKhoiVo! Thanks for your contribution! I will check it out after I finish with the PR for gfootball. I plan to finalize the changes and merge windows branch once I have enough time.

I thought that cmake's --config Release adds O2 flag automatically, but indeed LTCG might squeeze in some additional performance.

VOM7HC commented 3 years ago

I can't find any document or link say cmake add O2 automatically when we switch to Release, so I added it manually.

Note: it just improve CPU usage, FPS still drop sometime, so we need more time to cleanup game engine

vi3itor commented 3 years ago

I'm testing the PR and get the following warning after building: LINK : /LTCG specified but no code generation required; remove /LTCG from the link command line to improve linker performance. Do you have it too?

VOM7HC commented 3 years ago

Update comment: MSVC require so much. I use Visual Studio solution, which generated by CMake, then I added LTCG flag in properties window to build, for test performance. It may be auto add or remove some other flags when I add LTCG. Then I added LTCG back to cmakelist.txt. Now I will find solution, then update it again Reference issue and fix it from MS forum: Compiling with "Whole Program Optimization" but linker says no code generation required

VOM7HC commented 3 years ago

And linker performance is just effect to compile time, not effect to runtime anyway :smile:

VOM7HC commented 3 years ago

Hi @vi3itor, can you recheck again?

vi3itor commented 3 years ago

I checked, the warning is gone. Funny, the total size of the *.lib files is 1.3 Gb, with blunted2.lib along being 706 Mb. Since only an executable and .dll are required for running the game I will add an installation script to compile the game and remove unnecessary files. Probably even better is to improve CMakeLists.txt.

VOM7HC commented 3 years ago

Yeah, I think I will remove *.lib in another PR. This PR is just improve performance via flags compiler.