GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++ Performance Win

Libstdc++: Simplify std::shared_ptr internals

The `_Impl` classes inside `_Sp_counted_deleter` and `_Sp_counted_ptr_inplace` are removed, simplifying the internal layout of `std::shared_ptr`.

The _Impl classes inside _Sp_counted_deleter and _Sp_counted_ptr_inplace are removed. This change simplifies the internal layout of std::shared_ptr by flattening these classes now that empty base optimization (EBO) is no longer used, streamlining memory management and potentially improving performance.

In Details

This commit refactors the internal structure of std::shared_ptr by removing the _Impl classes from _Sp_counted_deleter and _Sp_counted_ptr_inplace. These _Impl classes were used to leverage EBO, but with the adoption of [[no_unique_address]], they're no longer necessary. This change primarily affects the library's internal ABI and memory layout, specifically in shared_ptr_base.h. Toolchain devs should note the removal of _M_impl and its replacement with direct data members.

For Context

std::shared_ptr is a smart pointer in C++ that automatically manages the lifetime of dynamically allocated objects. It keeps track of how many shared pointers point to the same object, and when the last shared_ptr is destroyed, the object is automatically deleted. The internal implementation uses techniques like Empty Base Optimization (EBO) to reduce memory overhead. This commit simplifies these internal structures, potentially leading to better performance and a more streamlined ABI.

Filed Under: libstdc++shared_ptrrefactoringmemory management