Skip to content

Commit

Permalink
Unconditionally change std::string's alignment to 8.
Browse files Browse the repository at this point in the history
    Save memory by providing the allocator more freedom to allocate the most
    efficient size class by dropping the alignment requirements for std::string's
    pointer from 16 to 8. This changes the output of std::string::max_size,
    which makes it ABI breaking.

    That said, the discussion concluded that we don't care about this ABI
    break and would like this change enabled universally
  • Loading branch information
EricWF committed Jan 22, 2024
1 parent 1000cef commit 7523a56
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 27 deletions.
5 changes: 0 additions & 5 deletions libcxx/include/__config
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@
// The implementation moved to the header, but we still export the symbols from
// the dylib for backwards compatibility.
# define _LIBCPP_ABI_DO_NOT_EXPORT_TO_CHARS_BASE_10
// Save memory by providing the allocator more freedom to allocate the most
// efficient size class by dropping the alignment requirements for std::string's
// pointer from 16 to 8. This changes the output of std::string::max_size,
// which makes it ABI breaking
# define _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT
# elif _LIBCPP_ABI_VERSION == 1
# if !(defined(_LIBCPP_OBJECT_FORMAT_COFF) || defined(_LIBCPP_OBJECT_FORMAT_XCOFF))
// Enable compiling copies of now inline methods into the dylib to support
Expand Down
7 changes: 1 addition & 6 deletions libcxx/include/string
Original file line number Diff line number Diff line change
Expand Up @@ -1937,12 +1937,7 @@ private:
return (__s + (__a - 1)) & ~(__a - 1);
}
enum {
__alignment =
#ifdef _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT
8
#else
16
#endif
__alignment = 8
};
static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type __recommend(size_type __s) _NOEXCEPT {
if (__s < __min_cap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@

#include "test_macros.h"

// alignment of the string heap buffer is hardcoded to either 16 or 8

const std::size_t alignment =
#ifdef _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT
8;
#else
16;
#endif
// alignment of the string heap buffer is hardcoded to 8
const std::size_t alignment = 8;

int main(int, char**) {
std::string input_string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@

#include "test_macros.h"

// alignment of the string heap buffer is hardcoded to 16

static const std::size_t alignment =
#ifdef _LIBCPP_ABI_STRING_8_BYTE_ALIGNMENT
8;
#else
16;
#endif
// alignment of the string heap buffer is hardcoded to 8
static const std::size_t alignment = 8;

template <class = int>
TEST_CONSTEXPR_CXX20 void full_size() {
Expand Down

0 comments on commit 7523a56

Please sign in to comment.