cpp-netlib: Moving Away from Header-Only
Posted in C++ on December 31st, 2010 by AdminToday I pushed the initial step for cpp-netlib to move away from having a header-only design. Yes, the project has come to a point where a decision had to be made: lower compile-time requirements and wider acceptance, or high compile-time requirements and limited acceptance. Until earlier today, builds of the cpp-netlib test suite had already been taking orders of minutes to build all the tests. I’m not talking about two minutes, I’m talking about multiples of 10 minutes on a reasonably powered machine. The whole test suite is an exhaustive suite of tests meant to make sure that the implementation is doing what it’s supposed to do. This limited my personal productivity as a developer, and the productivity of the users of the library developing other things on top of cpp-netlib. Something had to give and today I made the necessary changes to make that happen in 0.9.
Earlier on in the project, I really stuck to the “header-only” nature of the library. This was because I was convinced that the gains were really worth the costs. This is still largely true but there are a few compromises that had to be made. In this case the sacrifice was the added step of linking in an external static library for anything that is using cpp-netlib in their project.
The Change
First things first, not all the parts that I want to move out to static libraries have been moved out yet. The thing that requires the most compile time were the parsers — specifically the URI parser. I made very little changes to make the transition of the parser from a header-only parser implementation into an external lib implementation. You can find the relevant change set and the commit message through this link.
Just doing this has cut down the build time of the whole test suite by 60%. It used to take 10 minutes, and now the whole test suite just builds in around 4 minutes. I’ll publish exact numbers at a later time but generally this improvement in compile time would be welcomed by those using the HTTP clients. Because the URI parsing is a really important part of the library and because that in itself makes cpp-netlib unique, savings on the compile-times can really mean big gains for users of the library all-around. This addresses most of the concerns that users (both current and future) have of the library.
Balance
The library will at some point keep most of the implementation header-only while the heavier parts that take a lot of compile time would generally be moved out to externally built libraries. This means, almost all of the parts of the library that use Boost.Spirit will be moved out to external libraries because these are the parts that cost the most compile time (so far, that I’ve identified). This allows developers working on the library (there are a handful of us doing this) can keep some of the implementations header-only — when the costs become unbearably high on the compilation side, moving them to an externally linked library is always an option.
I personally think this is a good direction to go and I’m thankful to those who have advised me to go this route. Some have been a little more vocal than others but generally I’ve listened and I think this really does improve the library’s usability.
Future Direction
There are still some parts of the implementation that do cost quite a bit of compile time — not all the Boost.Spirit based parsers have been moved out just yet, and the parsers that deal with HTTP headers may very well be a candidate for “externalizing” in the coming days. All the other goodies that come with library development — tracking down bugs, improving the build system, creating distribution packages for various platforms, and the good stuff — would require the help of more developers. The website needs some help too, and the team would really appreciate help in coming up with layouts, designs, and copy for the website.
Testers on various platforms and compilers would very much be welcome too, and I’m looking to start investing and setting up that company to ensure that cpp-netlib keeps getting developed as an open source project. That company will provide paid support licenses to those looking to get commercial-grade support for the library in their enterprise and or the applications they are building. I’m looking to set up a (paid) support forum for those wanting to get commercial-grade support for cpp-netlib — hopefully I can get that out of the way and set up soon, but in the meantime if you’re looking to get support, you can get in touch with me through this form.
As for content of the blog, don’t worry — the cpp-netlib updates will pretty much stop. I’ll be getting back to writing about generic programming in the coming week. I’ll just be taking a break this weekend and I’ll probably be writing a couple of lighter articles for light weekend reading. Look out for the weekly C++ roundup on Sunday (Philippine time).
Filed under: boost, cpp-netlib, project
![]()
C++ Soup!


