0

it seems like a lot of the code in boost are compiler-specific workarounds or different paths for different compilers (especially in components like mpl). My build time increases a lot when I use boost, even when I try to hide the big parts behind compiler-firewalls (PIMPL) or use precompiled headers.

Is there a way to pre-process the boost headers for the one compiler I'm actually using? I suspect that anything that makes the headers (significantly?) smaller will have some impact. Has anyone ever tested whether that would actually give speed improvements?

No idea whether that matters much for the actual answer, but I'm using Visual Studio 2010 primarily.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ltjax
  • 15,837
  • 3
  • 39
  • 62
  • Well, you can run the preprocessor over a copy of the files. Try it out, I'm pretty sure you'll fine Sumsa is correct. –  Feb 23 '11 at 13:03

2 Answers2

5

If you use precompiled headers, then that is preprocessing the headers on steroids. If PCH won't make a difference, then there is nothing you can do that will.

The compile time likely comes from excessive including or complex template instantiations, not from the size or complexity of the preprocessor.

Puppy
  • 144,682
  • 38
  • 256
  • 465
  • +1. And if this is not enough, this should be: http://stackoverflow.com/questions/645747/sharing-precompiled-headers-between-projects-in-visual-studio – Hertzel Guinness Feb 23 '11 at 21:38
4

I suspect that anything that makes the headers (significantly?) smaller will have some impact.

My guess is after you do this, you will be disappointed. What takes most time in a complex template libraries like boost is not preprocessing, but template parsing, instantiation and optimization.

You could perform an experiment which would show you the upper limit of what you can gain this way:

  • change your build settings so that sources are not compiled, only preprocessed (i.e. add /P /EP switch - Properties / C/C++ / Preprocess to a File = Yes)
  • rebuild your project and time how long it takes

I expect what you see will be a minor fraction of the project build time, and even this will be preprocessing a lot more than only boost headers, therefore the gain from preprocessing boost would be even smaller.

Furthermore, if you have already included boost in your precompiled header, the preprocessing was already done as part of that, and most likely you will gain nothing at all.

Suma
  • 33,181
  • 16
  • 123
  • 191
  • I agree that they probably take most of the time. But there might still be some gains from just optimizing the headers. I/O complexity can never be neglected. – ltjax Feb 23 '11 at 13:06
  • 1
    Ok, sorry to get back at this so late - I just tried compiling with /P /EP and the build times are almost identical to doing actual builds :-/ – ltjax Mar 15 '11 at 21:13
  • That is really unexpected. Data are always right, but are you 100 % sure you have the settings right? (When you do /P /EP, no compilation is done at all - only preprocessing. I find it really hard to believe all your build time would be exclusively the I/O and preprocessing) In my case one randomly selected file from a project takes 8-10 seconds to compile and 4-5 seconds to preprocess (I did not measure whole project, that would take too long). – Suma Mar 16 '11 at 08:25
  • Pretty sure (but never 100%, too often the PEBKAC) - it was generating ".i" files for every compilation unit too, which looked like preprocessed files (with a lot of extra empty space), so I assume it was working. I just rebuilt one project from my solution with those settings. Maybe it is worth noting that my files tend to be relatively small, so the relative overhead might be big. After all, there must be a reason that [unity-builds](http://buffered.io/2007/12/10/the-magic-of-unity-builds/) seem to speed up things. – ltjax Mar 16 '11 at 08:53
  • The benefit of unity builds is not only I/O/preprocessing, but also (or I would say mostly) that classes are parsed only once and templates are instantiated only once. – Suma Mar 16 '11 at 08:59