You are not logged in.

#1 2025-08-24 08:36:19

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 893

New GCC versions slow down the compilation

I noticed that every new release of GCC tends to slow down the compilation time of C++ code. According to my findings (e.g. this) this might be due to newer features and code checks introduced with every new version. While this is certainly a good thing, with GCC 15 the situation has become quite unmanageable on my machine, and my daily work is slowed down in a way that is not bearable. So I'd need to understand which are the compiler options that can improve things a bit. Thanks in advance for any help.

Offline

#2 2025-08-24 11:22:03

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 14,310

Re: New GCC versions slow down the compilation

you are using makepkg/devtools to build, right ?

If yes, are you aware of https://wiki.archlinux.org/title/Makepkg#Optimization ?
One tip I use often for CMake build system in makepkg :
Use options=(debug strip) as it is faster then building targets like ReleaseWithDebInfo .

Using ccache can also speed up things, especially if your compile jobs are of the same software with small changes.

When compiling multi-threaded every job needs memory .
At some point adding jobs causes longer compilation times.
Ninja is especially prone to this.

Last edited by Lone_Wolf (2025-08-24 11:22:24)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#3 2025-08-24 12:43:20

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 69,068

Re: New GCC versions slow down the compilation

https://www.reddit.com/r/cpp/comments/1 … as_gcc_13/ discusses "--enable-checking" but that's not new and commenting it will only default to "yes"
What specifically compiles "slow" with what flags? (I don't think that the static analysis is enabled by default?)

Offline

#4 2025-08-24 15:05:52

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 893

Re: New GCC versions slow down the compilation

@Lone_Wolf I am building my own software, not packages with PKGBUILD, sorry for not being clear about this. ccache seems a nice tip, I'll give it a try. Currently I am using CMake with make, and I usually compile with `-j12` so not many processes; anyway I see similar slowness also with sequential builds.

@seth I am not sure about that thread, but I didn't find much more about this topic. If I correctly understand, the `--enable-checking` flag is a build-time flag for building GCC, not for compiling software; so I was wondering if there is any compiler flag to disable its effect. Probably I am shooting in the dark...

Offline

#5 2025-08-24 15:28:35

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 893

Re: New GCC versions slow down the compilation

@Lone_Wolf Unfortunately ccache does not work very well for my use case. I have a project with some headers which are included by several source files, and touching them (which happens quite often in this development stage) triggers a rebuild of many source files which cannot benefit of ccache. Maybe precompiled headers could yield more benefits in this use case?

Offline

#6 2025-08-24 18:30:39

seth
Member
From: Don't DM me only for attention
Registered: 2012-09-03
Posts: 69,068

Re: New GCC versions slow down the compilation

--enable-checking isn't particularly new, it's unlikely to have caused slowdowns between gcc 13 and gcc15

seth wrote:

What specifically compiles "slow[er]" with what flags? (I don't think that the static analysis is enabled by default?)

Please post an example gcc output.

gcc9/10/11/12/13 are btw. still in the repos, have you checked that their performance is actually better *right now* and this isn't because of unrelated changes?

Offline

#7 2025-08-25 10:05:41

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 893

Re: New GCC versions slow down the compilation

@seth I did a compile check with GCC 11, 14 and 15, and the build times are actually quite similar. So either my feelings are totally wrong, or there is something in my project that slowed down the compilation. Actually I switched to C++20 around  the time GCC 15 became available, so that might be the reason.

Thanks to everybody for the suggestions, and sorry for the noise.

Offline

#8 2025-08-25 12:10:08

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 14,310

Re: New GCC versions slow down the compilation

snack wrote:

Unfortunately ccache does not work very well for my use case

ccache -s / --status can shed some light on the reason of misses.

arch wiki wrote:

ccache also by default caches the current directory being used for each build, which means cache misses for build pipelines that use a new, random temporary directory each time it is called.

This can be workedaround but may need changes in compilerflags. see compiling in different directories


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#9 2025-08-25 12:18:37

snack
Member
From: Italy
Registered: 2009-01-13
Posts: 893

Re: New GCC versions slow down the compilation

Lone_Wolf wrote:

Unfortunately ccache does not work very well for my use case

If I'm correct then it's not a matter of misses. ccache can speed up the re-build of a file (or better, translation unit) that didn't change since the last build, but when I modify a header this actually modifies all the translation units including it. Thus ccache cannot be of help here, while precompiled headers could be (but I'm facing issues with PCH and CMake, eventually see here).

Offline

Board footer

Powered by FluxBB