开发者

Remove compiler-specific code from boost headers

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 St开发者_Python百科udio 2010 primarily.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜