From 9c1ac3702e7849a6a144efd9a0acc22ce7e4ee90 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Fri, 8 Nov 2024 20:54:00 -0800 Subject: [PATCH] Move index closer to start of Node{3,16} This should slightly improve cache hit rate --- ConflictSet.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ConflictSet.cpp b/ConflictSet.cpp index c33dce5..8809fc4 100644 --- a/ConflictSet.cpp +++ b/ConflictSet.cpp @@ -338,11 +338,12 @@ struct Node3 : Node { constexpr static auto kMaxNodes = 3; constexpr static auto kType = Type_Node3; - TaggedNodePointer children[kMaxNodes]; - InternalVersionT childMaxVersion[kMaxNodes]; // Sorted uint8_t index[kMaxNodes]; + TaggedNodePointer children[kMaxNodes]; + InternalVersionT childMaxVersion[kMaxNodes]; + uint8_t *partialKey() { assert(!releaseDeferred); return (uint8_t *)(this + 1); @@ -357,11 +358,12 @@ struct Node16 : Node { constexpr static auto kType = Type_Node16; constexpr static auto kMaxNodes = 16; - TaggedNodePointer children[kMaxNodes]; - InternalVersionT childMaxVersion[kMaxNodes]; // Sorted uint8_t index[kMaxNodes]; + TaggedNodePointer children[kMaxNodes]; + InternalVersionT childMaxVersion[kMaxNodes]; + uint8_t *partialKey() { assert(!releaseDeferred); return (uint8_t *)(this + 1); @@ -440,7 +442,10 @@ inline void Node3::copyChildrenAndKeyFrom(const Node0 &other) { inline void Node3::copyChildrenAndKeyFrom(const Node3 &other) { memcpy((char *)this + kNodeCopyBegin, (char *)&other + kNodeCopyBegin, kNodeCopySize); - memcpy(children, other.children, sizeof(*this) - sizeof(Node)); + memcpy(index, other.index, kMaxNodes); + memcpy(children, other.children, kMaxNodes * sizeof(children[0])); // NOLINT + memcpy(childMaxVersion, other.childMaxVersion, + kMaxNodes * sizeof(childMaxVersion[0])); memcpy(partialKey(), &other + 1, partialKeyLen); for (int i = 0; i < numChildren; ++i) { assert(children[i]->parent == &other);