boostorg / container

STL-like containers from Boost
http://www.boost.org/libs/container/
Boost Software License 1.0
96 stars 116 forks source link

Use sized delete in boost::container::new_allocator if __cpp_sized_deallocation is defined #210

Closed marksantaniello closed 1 year ago

marksantaniello commented 2 years ago

Boost container's new_allocator::deallocate ignores the size_type argument: https://github.com/boostorg/container/blob/develop/include/boost/container/new_allocator.hpp#L165-L166

If __cpp_sized_deallocation is defined, it would be nice to pass the size to operator delete, as done by libstdc++'s equivalent: https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/libstdc%2B%2B-v3/include/ext/new_allocator.h#L132-L134

As we argued back in 2019, this can reduce the cost of deallocation by up to 40%. https://gcc.gnu.org/legacy-ml/libstdc++/2019-02/msg00095.html

High-performance malloc implementations (jemalloc, tcmalloc) divide allocations into "size classes", and would otherwise require an address-to-size-class lookup at deallocation time. By reminding the allocator of the originally-allocated size, we can avoid the cost of this metadata lookup.

igaztanaga commented 1 year ago

Many thanks for the report!