为什么MSVC STL使用这种方式让两个对象共享同一个缓存行?

Plu*_*uto 6 c++ caching stl x86-64

以下是 MSVC STL 中的部分代码std::any

class any {
    // ...
    struct _Small_storage_t {
        unsigned char _Data[_Any_small_space_size];
        const _Any_small_RTTI* _RTTI;
    };
    static_assert(sizeof(_Small_storage_t) == _Any_trivial_space_size);

    struct _Big_storage_t {
        // Pad so that _Ptr and _RTTI might share _TypeData's cache line
        unsigned char _Padding[_Any_small_space_size - sizeof(void*)];
        void* _Ptr;
        const _Any_big_RTTI* _RTTI;
    };
    static_assert(sizeof(_Big_storage_t) == _Any_trivial_space_size);

    struct _Storage_t {
        union {
            unsigned char _TrivialData[_Any_trivial_space_size];
            _Small_storage_t _SmallStorage;
            _Big_storage_t _BigStorage;
        };
        uintptr_t _TypeData;
    };
    static_assert(sizeof(_Storage_t) == _Any_trivial_space_size + sizeof(void*));
    static_assert(is_standard_layout_v<_Storage_t>);

    union {
        _Storage_t _Storage{};
        max_align_t _Dummy;
    };
};
Run Code Online (Sandbox Code Playgroud)

我们可以看到,根据保存的对象的类型,主要存储部分是_Storage_t,这将是_Small_storage_t_Big_storage_t或者只是数组。unsigned charstd::any

我无法理解以下评论的含义_Big_storage_t

// Pad so that _Ptr and _RTTI might share _TypeData's cache line
unsigned char _Padding[_Any_small_space_size - sizeof(void*)];
Run Code Online (Sandbox Code Playgroud)

在我的平台上,一些参数的值为:

sizeof(void*);  // 8 bytes
constexpr int _Small_object_num_ptrs = 6 + 16 / sizeof(void*); // 8
constexpr size_t _Any_small_space_size = (_Small_object_num_ptrs - 2) * sizeof(void*); // 48
constexpr size_t _Any_trivial_space_size = (_Small_object_num_ptrs - 1) * sizeof(void*); // 56
sizeof(_Small_storage_t);  // 56 bytes
sizeof(_Big_storage_t);    // 56 bytes
Run Code Online (Sandbox Code Playgroud)

我的问题是

  1. 为什么_Padding允许_Ptr并与_RTTI共享缓存行_TypeData

  2. 这样做(共享缓存行)有什么好处?