GoingNative 35: Fast Tips for Faster Builds!

Play GoingNative 35: Fast Tips for Faster Builds!

The Discussion

  • User profile image

    May be you guys, put a caption on every C++ videos "Sorry for the Delay - Videos".
    Unfortunately, these are the only C++ stuff coming out and that too when you guys get to remember about it. You apologize for once or twice, not for every other post that comes out.

  • User profile image

    freefly, a fair point.   We'll endeavor to get these up on time.   Thanks for watching!

  • User profile image

    Very informative video! I do have some additional questions however.

    1. What is the compilation overhead of including an unused header like say <map>? Is there any way to get a warning when a header is included but never used so that I can go and remove it?
    2. What is the compilation overhead of including a header with class declaration vs simply a forward declaration? What about for inline template classes like stl? Is there any way for the compiler or the analysis tool to let me know when I'm including a class declaration when a forward declaration is all that is needed (like <iosfwd>)?


  • User profile image

    One speedup (not large, but something) we implemented pretty simply involves manipulating %TEMP%.

    On our standard machine configuration, there are two partitions (C: and D:). C: contains what it normally would (including user profiles and default %TEMP%), while D: usually contains all of our code.

    A while ago I guessed that since the build process utilizes %TEMP% pretty heavily, some of that might include moving files between %TEMP% and your build output locations. If everything is on the same partition, file moves are instantaneous, but if they're on separate partitions you're going to pay the price of a copy/delete.

    What we tried was to "wrap" our build process with a batch file that changes %TEMP% while the build runs so that it sees %TEMP% on the same partition as the code and build output:


    IF /I "%1" == "create" (
            FOR %%f IN ("%CD%") DO SET BUILD_TEMP=%%~sf\BUILD_TEMP
        IF DEFINED TMP (
            IF /I "%CD:~0,1%" NEQ "%TMP:~0,1%" (
                SET TMP=!BUILD_TEMP!
            IF /I "%CD:~0,1%" NEQ "%TEMP:~0,1%" (
                SET TEMP=!BUILD_TEMP!
        ECHO Create !BUILD_TEMP!
        GOTO Done
    IF /I "%1" == "remove" (
        ECHO Remove !BUILD_TEMP!
        IF /I "!BUILD_TEMP!" NEQ "" (
            RMDIR /S /Q !BUILD_TEMP!
        GOTO Done

    So we just run that from the source directory with "create", do our build, then run it again with "remove".

    We got a minor speedup so we didn't do any in-depth analysis to confirm our suspicion, but I would like to hear more from you guys.

    Your mileage may very, but it's pretty easy to do and every little bit helps :)

  • User profile image
    Sridhar Madhugiri


    Including unused headers has an impact on the build time / working set of the compiler. The cost of unused header varies based on their content. Size of the header, number of symbols and types in the file all impact build time. In general, Template heavy code with inline definition of methods imposes a higher penalty than “C” style headers with function declarations and struct definitions.

    Warning about “just need a forward declare” is an interesting idea. We have a number of other ideas on our backlog to identify patterns that impact build times. Ideally we want to surface as many of the issues as possible at design time and have a switch in the compiler that identifies issues that cannot be detected at design time.

    Thanks for the feedback!

  • User profile image
    Dustin Land

    The OS file cache can have a significant impact on subsequent run times for a test like the PCH one you conducted. I'd be curious to see the compile time after a cold boot.

  • User profile image

    I enabled Project Timings on our solution (containing around 200 projects), and I can see that a significant amount of time (around 750 seconds) is being spent on ResolveProjectReferences.

    What does that phase cover, exactly? Is that 750 seconds of actual work, or is it time spent waiting for a dependency to complete building, or something like that?

    Is there anything I can do to speed up this specific task?

  • User profile image

    I love all the warnings flying by in the PCH demo. :P

  • User profile image
  • User profile image

    Thank! you!
    I feel my Visual Studio run faster now after I re-config something. (Disable Auto update)

  • User profile image
    Yossi Zinger

    Suppose I have a C++ file that takes a long time (over 5 minutes) to compile. I understand Microsoft wants to get information about this. Who should I contact?

  • User profile image

    @Yossi Zinger: Contact sridmad and aasthan, both at microsoft dot com.

    @jalf: I'd encourage you to do the same; sorry for the delay!

  • User profile image
    Rohit Jainendra

    Hi all, encourage you to also check out Huddle and ElectricAccelerator from Electric Could to speed up your builds and tests with guaranteed accurate results.

Add Your 2 Cents