3

Lets stick with one file and one header. I generate a header which has lots of information in it and i make a light version of that header with many methods removed. The header went from 6k lines to 3k.

Here is an example of how a class looks like in the light header

class SomeClass : public MACRO_FOR_KEYWORD TheBase {
    virtual void i_dont_filter_this_out(){}
public:
    deque<Var*> ls;
    inline SomeClass(){}
    inline virtual ~SomeClass(){}
    inline SomeClass(deque<Var*> ls_)
    {
        ls = ls_;
    }
};

I tried compiling the same file and it went from 8seconds to 7seconds... Not the results i was hoping for.

I'm thinking maybe the majority of the compile time is because i am defining so many classes and the methods don't matter. But i need all thoses classes to exist. Theres about 280 classes. I don't think thats many.

What can i do to lower my compile time? Should i bother? Its about 9seconds per file and linking is another few seconds. I don't suppose i can do anything but get a faster CPU?

Note: I am using visual studios.

  • Possible duplicate of [What techniques can be used to speed up C++ compilation times?](http://stackoverflow.com/questions/373142/what-techniques-can-be-used-to-speed-up-c-compilation-times) and [How do YOU reduce compile time, and linking time for Visual C++ projects? (native c++)](http://stackoverflow.com/questions/364240/how-do-you-reduce-compile-time-and-linking-time-for-visual-c-projects-nativ) – In silico Feb 06 '12 at 01:43
  • 1
    is this header automatically generated? 3k lines seems like a lot – Sam Miller Feb 06 '12 at 02:16

1 Answers1

1

You can export your definitions -- assuming of course you include this header elsewhere. 280 classes is quite small when you look at larger projects or libraries like boost. Do these classes all belong together - or can they not be separated into smaller groups to reduce dependency and compile times? Why should you favor a light header (with redundant declaration?) over an approach such as a unity build?

justin
  • 104,054
  • 14
  • 179
  • 226
  • The light file turned out not to matter so i wont bother using it. Good thing i didnt spend much time on it (its actually my larger header with a pass to remove lines contain certain strings). I know removing a few std headers (cassert, cstdio) and using iosfwd instead of i and o stream it went down another second. Its just strange these files take several seconds to compile. I'll need to work on these files a lot (they are big) –  Feb 06 '12 at 00:49
  • @acidzombie24 ok - the light file could wind up being a pain to maintain and keep in sync. perhaps you can reconsider how you use PCH files? still, 3KSLOC == 7 seconds is sloooow if the dependencies are trivial. – justin Feb 06 '12 at 01:04
  • I'm also using gcc but i havent tested on gcc which i should actually do know. I only know my build does work just not how long. Funny enough a rebuild is only 45seconds. Maybe its actually the linker. Ok i tried building a blank file, its about 1-2 seconds. I guess deque (which i need) + the headers are about 3-4seconds + 2linker + 1sec for the body. Thats not so bad. Still 7-8second build when i need to do lots of small things is a bit annoying. -edit- +1 –  Feb 06 '12 at 01:19
  • hmm - still sounds slow. try the build time links In silico posted (above) if it continues to bother you. there are so many directions you can take to optimize build times - i can only offer blind advice/generalizations at this point. – justin Feb 06 '12 at 02:47