Another cool MSVC flag: /d1reportTime

A while ago I found about a fairly useful Visual C++ flag that helps to investigate where the
compiler backend/optimizer spends time – /d2cgsummary, see
blog post.

Turns out, there is a flag that reports where the compiler frontend spends time – /d1reportTime.

I’ve been writing about lack of compiler time profiling/investigation tools, starting from that
same old post, up to the more recent ones
that focused on clang - one
and two.
All this recent discussion about C++ compilation times (among other issues…) led me
to finding this fresh project on github,
UECompileTimesVisualizer by
@phyronnaz. Ignore everything
about UE4 there (unless you work with it of course :)), the new thing for me was that it says:

Add the following arguments to the C/C++ Command Line option in your project settings: /Bt+ /d2cgsummary /d1reportTime

/Bt+ and /d2cgsummary are known, but /d1reportTime I haven’t heard about before. What is it?!
The only other place on the internet that talks about it – and it’s fairly impressive for anything to have just two mentions
on the internet – is a small comment in Microsoft
forums thread a couple months ago, and the only thing it says
is: “Can you also share the output from /d1reportTime?”

So what is /d1reportTime?

Passing /d1reportTime to the MSVC compiler (cl.exe) will make it print:

Which header files are included (hierarchically), with time taken for each,

Which classes are being parsed, with time taken for each,

Which functions are being parsed, with time taken for each.

Additionally, at end of each list, “top N” are listed too. List of classes/functions seems to contain
info about which templates (or nested classes? not sure yet) are being instantiated as well.

I have no idea which version of MSVC the flag has appeared in. VS2015 seems to not have it yet; and
VS2017 15.7 (compiler version 19.14.26428) already has it; it might have appeared in earlier VS2017 builds
but I haven’t checked.

Running it on anything non-trivial produces tons of output, e.g. I randomly ran it on a (fairly big)
Shader.cpp file we have in our codebase, and it produces 30 thousand lines of output. Shortened a lot:

At 30k lines it is not the most intuitive for manual use, but a lot of interesting information is there.
Particularly the “Top N” lists sound like good things to start with, if looking at the output manually.

Having reports like that is also useful to realize just how much work we’re asking the compiler to do.
The C++ snippet above is “as simple as it gets” when using “standard” C++ features. Just make a vector
of integers, and add a number to it. The compiler ends up including 74 headers, parsing over 800 classes and
almost 800 functions. Just to make a simple “push an integer into a vector” task.

Yes, I know about precompiled headers. And I know about upcoming C++ modules.
You can save on sending that email :)

Anyway, having that tooling is really good! Thanks Microsoft Visual C++ team!
Also, u/gratilup mentions in
this reddit thread
that MSVC team is working on ETW/WPA based tooling to visualize compilation times. Great!