How to reduce compilation times with Boost Asio

前端 未结 4 440
南旧
南旧 2021-01-14 09:14

Boost.Asio is great library but it has one huge drawback -- extreamly slow compilation times. A simple implementation (really simple) of HTTP protocol (about 1k lines of cod

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-14 10:21

    Well, you probably solved this long ago. But just in case.

    Precompiled headers do not magically improve compilation times. They improve cross-translation-unit compile times by cacheing the first header evaluation. Thus you won't see a benefit unless you are #includeing ASIO across multiple source files. Any new template instantiations will further make this last benefit even less noticeable.

    I suggest isolating ASIO to a single source file. Don't include ASIO in any 'non-detail' header files. If you must do the latter, try to hide it by using the Pimpl pattern.

    If you find yourself requiring ASIO functionality in multiple source files, then think about building an abstraction layer between your code and ASIO. If you keep it as simple as possible, ensuring the bridging code never changes, then you can even #include this interface in the PCH.

提交回复
热议问题