Like Tree1Likes
  • 1 Post By cpjust

Why do pre-compiled headers make my build take longer?

This is a discussion on Why do pre-compiled headers make my build take longer? within the C++ Programming forums, part of the General Programming Boards category; Hi, I just tried using a pre-compiled header for a large C++ build on Solaris to try to speed it ...

  1. #1
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545

    Why do pre-compiled headers make my build take longer?

    Hi,
    I just tried using a pre-compiled header for a large C++ build on Solaris to try to speed it up, but it ended up slowing it down (from ~94 mins to ~111 mins).

    The method I used was to get a list of all 3rd party header files used in the project and stick them in 3rdParty.h which I pre-compiled and then I just changed the Makefiles to add -include path/3rdParty.h to all the g++ lines. This way I didn't have to change hundreds of .cpp files.

    Is this the wrong way to use pre-compiled headers?
    Why does this take longer?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Before speculating much, have you familiarized yourself with all of this information:

    Precompiled Headers - Using the GNU Compiler Collection (GCC)

    You probably have, but...
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Yeah, I took a look at that page.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    OK, I just added a -H flag to g++ and it's saying that the pre-compiled header isn't being used.
    Code:
    x /tmp/myapp/3rdParty.h.gch
    It should have a ! if it was used.
    I used exactly the same compiler flags to build the .gch file as I'm using to build the .cpp files (except the .cpp files also have some -I flags).
    stahta01 likes this.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Crap! Nevermind. My .gch file was also using a -M option that the .cpp files weren't. Now it's using the .gch file.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    OK, in case anyone is interested, I managed to cut the build time by 33% by only including the 20 top included header files (I used a script that counts how many times each header file is included) instead of including all 3rd party header files in my pre-compiled header.

    So when using pre-compiled headers, choose which headers are pre-compiled carefully by measuring how many times each one is included.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling GNU MP
    By mattnp12 in forum C Programming
    Replies: 3
    Last Post: 06-23-2011, 03:58 PM
  2. How to build, run Boland C++ 6 source file via VS2005?
    By userpingz in forum C++ Programming
    Replies: 2
    Last Post: 05-21-2009, 03:25 AM
  3. Replies: 1
    Last Post: 03-12-2008, 12:10 AM
  4. New compiler - Weird errors -,-.
    By Blackroot in forum C++ Programming
    Replies: 8
    Last Post: 08-27-2006, 07:23 AM
  5. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21