Decrease build time using C/C++ incomplete types/forward declaration#1963
Decrease build time using C/C++ incomplete types/forward declaration#1963GermanAizek wants to merge 2 commits intohtop-dev:mainfrom
Conversation
…ration References: - https://www.gnu.org/software/c-intro-and-ref/manual/html_node/Incomplete-Types.html - https://stackoverflow.com/questions/73586567/how-does-forward-declaration-save-compile-time - https://www.reddit.com/r/cpp/comments/84ewn5/forward_declarations_to_reduce_compiletime/ - https://arne-mertz.de/2018/03/forward-declarations/
|
Im fixed merge conflicts to master branch. |
|
Related: #1460 |
Wow cool many thanks for trying to promote this feature too, since building 16 seconds on a single thread is really a lot considering that htop is a small utility on my 72 thread CPU, 72 packages are compiled in parallel. I'm trying to push forward declarations into many large packages as it helps developers save time and users of source-based distributions. |
|
NetBSD action is dead:
|
I'm not promoting it actually. I just provide an info that a forward declaration patch I proposed before was rejected. For reducing compilation time, forward declaration can help. But it seems like the maintainers don't like It might help clean up some readability mess by declarations like |
|
In fact IWYU actually tries to stear you towards forward declarations in its default settings, but we decided to avoid them as maintaining these forward declarations introduces additional overhead of maintaining where they need to be kept and where a symbol is actually provided. Thus in order to have a clear single point of declaration the use of forward declarations is avoided when possible. There are some places that use forward declarations, but these are necessitated by the code structure. That said, the bare struct Foo_ is just plain ugly and much too verbose; and yet another reason not to use these forward declarations unless absolutely necessary. |
Dear contributors and maintainers,
I use the source-based distro Gentoo and every system update is a pain to build a huge number packages from sources with waste time, AUR Arch Linux fans agree with me.
This simple change will help both users of source-based distributions and developers, as the build speed is reduced in the Hyperfine single-core build test.
My benchmark on E5-2699v3 (1 core)
Before
After
Difference compile time: -12%
References about technique: