c++c++11move-semanticsintrusive-containersboost-intrusive

Do Intrusive containers still have performance advantages over non-intrusive ones in modern C++?


Do Boost.Intrusive containers still have performance advantages over non-intrusive standard (std::) ones in the modern C++ (with move semantic, emplace_back, etc)?


Solution

  • Yes, there are numerous advantages of intrusive containers that still remain even when move semantics are used with STL containers. In particular, memory locality is still likely going to be better, which can yield great performance gains in certain scenarios. Also, iterators can still benefit greatly, and avoiding any overhead from exceptions can speed up insertion/deletion operations.

    Consider Table 19.1 from the Intrusive and non-intrusive containers section of the Boost reference. Most of these advantages likely remain, such as:

    The Boost documentation has detailed performance metrics which show the relative performance of a wide variety of operations in different scenarios. If you consider which of these is not affected primarily by allocation, there is still considerable potential.

    Of course, ultimately the question of performance and optimality is going to depend primarily on your particular application, so it is inadvisable to make generalised statements about the "best" or "fastest" approach. There is no substitute for profiling your particular code and assessing the tradeoffs involved with the additional complexity.