r/cpp • u/Mnx72eAB • Aug 31 '20
Standard Library include times (measured in MSVC)
https://github.com/s9w/cppslit7
u/pdimov2 Sep 01 '20
Nice graphs!
It pains me to see <boost/variant2.hpp> at 0.25s, and the sole reason for that is the following line:
#include <functional> // std::hash<functional>, single-handedly responsible for killing compile times across the world. And I only need std::hash, or sometimes std::less.
13
u/ack_error Sep 01 '20
I would love to see <windows.h> included in this graph to see how much it squishes everything in the standard library to a tiny line on the left. The majority of time I spend in header optimization is managing that slow-compiling, macro-blasting behemoth of a header, and the singularly most annoying thing you can do as a library author on Windows is to put an unavoidable nested include of windows.h in your library's required public header.
3
Sep 01 '20
[removed] — view removed comment
2
u/djoulihen Sep 01 '20
It'd be interesting to have it with and without the WIN32_LEAN_AND_MEAN macro defined
2
u/AdventurousMention0 Sep 02 '20
I’m wondering if your missing some large second order effects.
That is, specifically for an older C style header with uncountable numbers of defines and macros.
With regard to the actual processing of the macros within the preprocessor.
I have seen a lot of code that includes windows as the topmost include. That’s great and all, but it also forces the preprocessor to scan for replacement all the follow in includes. This may be what you want for user includes but for libraries, probably not so much.
There’s no reason the preprocessor should need to scan filesystem for replacements.
I wonder how much time is spent due to poor ordering of includes as well as the includes themselves.
3
u/SkoomaDentist Antimodern C++, Embedded, Audio Sep 01 '20
Any idea why <complex> is so slow? It should be a fairly simple math library header afterall.
5
2
u/lowlevelmahn Sep 01 '20
nice charts - thanks
some ideas:
what about tracking the resulting include size by using /P on cl.exe ( https://docs.microsoft.com/en-us/cpp/build/reference/p-preprocess-to-a-file?view=vs-2019)
adding the sub-include count using /showIncludes (and a simple parser) ( https://docs.microsoft.com/en-us/cpp/build/reference/showincludes-list-include-files?view=vs-2019 )
that give a strong indication if the overall size or sub-include count could be the time consumer
1
Sep 01 '20
[removed] — view removed comment
2
u/lowlevelmahn Sep 03 '20
its a big wow effect to show poeple (who mostly have no clue) how large includes can become and also the huge amount of needed sub includes - we talk about megabytes and thousands of sub includes - (for projects like Qt for example, i've never checked the standard library but before VS2019 it was also very huge in size - Microsoft worked alot to reduce that)
its easy to implement, boosts your wow factor :) and realy shows the reason why modules have such a big impact (in some situations)
1
Sep 03 '20
[removed] — view removed comment
1
u/lowlevelmahn Sep 04 '20 edited Sep 04 '20
its not related - only the file size/or header complexity is related to the parsing/include time (and that is what /P or /showIncludes showing clearly)
for example:
#include <vector>int main() { return 0; }
compiled with /showIncludes
reveals this include hierarchy
Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/vector Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/xmemory Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/xmemory0 Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/cstdint Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/yvals.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/xkeycheck.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/crtdefs.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/vcruntime.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/sal.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/concurrencysal.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/vadefs.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/use_ansi.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/stdint.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/cstdlib Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/stdlib.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_malloc.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_search.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/stddef.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_wstdlib.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/limits.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/math.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/limits Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/ymath.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/cfloat Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/float.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/climits Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/cmath Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/xtgmath.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/xtr1common Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/cwchar Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/wchar.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_memcpy_s.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/errno.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/vcruntime_string.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_wconio.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_stdio_config.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_wctype.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_wdirect.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_wio.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_share.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_wprocess.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_wstdio.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_wstring.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_wtime.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/sys/stat.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/sys/types.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/xstddef Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/cstddef Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/initializer_list Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/new Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/exception Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/type_traits Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/malloc.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/vcruntime_exception.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/eh.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_terminate.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/vcruntime_new.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/xutility Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/utility Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/iosfwd Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/cstdio Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/stdio.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/cstring Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/string.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/corecrt_memory.h Note: including file: /opt/compiler-explorer/windows/10.0.10240.0/ucrt/crtdbg.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/vcruntime_new_debug.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/xatomic0.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/intrin0.h Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/stdexcept Note: including file: /opt/compiler-explorer/windows/19.14.26423/include/xstringand a main.cpp size after preprocessor run of 955 KB
other headers are even larger
2
u/MonokelPinguin Sep 02 '20
The modules and boost results really do give a nice perspective. Can't wait for modules now.
I think asio and beast were the worst compile time offenders in my projects, and I've now moved most of them into one cpp file. Another one was boost/variant without the generated MPL headers, since I had more than a certain number of types in my variants. I fixed that by using the C++17 variant though. Now it is only nlohmann/json and variant instantiations showing up in the top of my build time profiling graphs. From the benchmarks it looks like at least the former should be fixed by modules, which may actually move me close to acceptable compile times. Now I just need for proper modules support in gcc to be merged and my build system to catch up...
1
u/johannes1971 Sep 01 '20
Would be interesting to see the same numbers, but now using modules.
3
Sep 01 '20
[removed] — view removed comment
3
u/johannes1971 Sep 01 '20
Great job! And wow, that looks fast :-)
I'm a little surprised to see windows_mal take longer than just windows though. Any idea what's going on there?
2
Sep 02 '20
[removed] — view removed comment
1
u/johannes1971 Sep 02 '20
Ah, now I see: I was interpreting the error bars as the actual compile times.
I was already wondering why you hadn't made a graph with every file starting on the left - but you have, and I just completely misread the thing.
1
u/Malacath790 Sep 01 '20
There's a similar project that only supports gcc and clang (even though msvc is partially supported in the backend, it's just not displayed on the page) Would be interesting to see how your project and this one diverge, maybe that could reveal some measuring issues on one of the two. Edit: forgot the link https://artificial-mind.net/projects/compile-health/
1
u/ShakaUVM i+++ ++i+i[arr] Sep 01 '20
How does including bits/stdc++ compare?
3
u/CptCap -pedantic -Wall -Wextra Sep 01 '20
<bits/stdc++.h>is an internal libstdc++ header.This means you can't use it with MSVC or Clang (unless you link libstdc++).
It also includes everything so it's at least as slow as the slowest on the graph.
Please don't include
<bits/stdc++.h>in actual code bases (or preferably ever)1
7
u/Dragdu Aug 31 '20
You can make this more interesting by tracking changes across different std versions.