SuperTux / supertux

SuperTux source code
https://supertux.org
GNU General Public License v3.0
2.5k stars 479 forks source link

Support pre-compiled headers and interprocedural/link-time optimisation #2978

Open Semphriss opened 3 months ago

Semphriss commented 3 months ago

This adds CMake code to enable pre-compiled headers (PCH) and interprocedural optimisation (IPO, or LTO for link-time optimisation).

PCH

PCH makes builds 50% to 66% faster. A simple time make -j$(nproc) on my 12-core CPU shows:

With PCH:
real    0m58.048s
user    5m33.425s
sys    1m56.666s

Without PCH:
real    1m50.533s
user    15m20.049s
sys    2m56.815s

real is the total time spent, from start to finish, as perceived by the developer. user is the sum of the time spent by each thread, which gives a better idea of what would happen on a single-threaded system. Details

IPO

IPO makes Release builds 15% smaller. I have not tested the runtime performance.


Notes

Semphriss commented 3 months ago

I had to change a few more things in the code for the builds to pass. I changed it to the best of my abilities, but some involve design choices, so it might be good to review them. The diff will show all the changes, but I bumped the minimum CMake version from 3.1 to 3.9 to support policy CMP0069 (needs 3.6) and list(FILTER ...) (requires 3.9). Let me know if you'd like to change something.

tobbi commented 3 months ago

I tested this a couple days ago. Seems to be working fine.

HybridDog commented 3 months ago

This sounds like enabling pre-compiled headers has only advantages and no disadvantage. If a developer edits a single header file and recompiles the program, is the recompilation faster or slower with pre-compiled headers enabled?

Semphriss commented 3 months ago

@HybridDog It's something I've been thinking about, whether or not to enable them by default. They're not really relevant during development, only when making releases, which is IMO the preferred place for lesser-known non-default options to live.

I haven't tried actively developing with those options enabled, but I would presume, especially with LTO, that it substantially slows down development compiling. I'm not sure how large the impact is, and active developers would be better placed to report their experience with that.

HybridDog commented 2 months ago

If they are only relevant for release builds, maybe they can be enabled if and only if the build type is Release or RelWithDebInfo (-DRELEASE).

Semphriss commented 2 months ago

PCH and IPO are now only enabled on Release|RelWithDebInfo builds.