Still need a better way identify left/right sidedness
This commit is contained in:
65
Bench.cpp
65
Bench.cpp
@@ -1,4 +1,5 @@
|
|||||||
#include "ConflictSet.h"
|
#include "ConflictSet.h"
|
||||||
|
#include "Internal.h"
|
||||||
|
|
||||||
#define ANKERL_NANOBENCH_IMPLEMENT
|
#define ANKERL_NANOBENCH_IMPLEMENT
|
||||||
#include "third_party/nanobench.h"
|
#include "third_party/nanobench.h"
|
||||||
@@ -15,7 +16,7 @@ std::string toKey(int n) {
|
|||||||
|
|
||||||
constexpr int kNumKeys = 100000;
|
constexpr int kNumKeys = 100000;
|
||||||
|
|
||||||
int main(void) {
|
void benchPointRead() {
|
||||||
ankerl::nanobench::Bench bench;
|
ankerl::nanobench::Bench bench;
|
||||||
|
|
||||||
int readKey = kNumKeys / 2;
|
int readKey = kNumKeys / 2;
|
||||||
@@ -43,3 +44,65 @@ int main(void) {
|
|||||||
ConflictSet::Result result;
|
ConflictSet::Result result;
|
||||||
bench.run("point read", [&]() { cs.check(&r, &result, 1); });
|
bench.run("point read", [&]() { cs.check(&r, &result, 1); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void benchPointerSet() {
|
||||||
|
ankerl::nanobench::Bench bench;
|
||||||
|
|
||||||
|
constexpr int kNumPointers = 32;
|
||||||
|
bench.batch(kNumPointers);
|
||||||
|
|
||||||
|
std::vector<void *> pointers;
|
||||||
|
for (int i = 0; i < kNumPointers; ++i) {
|
||||||
|
pointers.push_back(malloc(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
bench.run("Create and destroy Arena hashset", [&]() {
|
||||||
|
Arena arena;
|
||||||
|
auto h = hashSet<void *>(arena);
|
||||||
|
for (auto p : pointers) {
|
||||||
|
h.insert(p);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bench.run("Create and destroy malloc hashset", [&]() {
|
||||||
|
std::unordered_set<void *, MyHash<void *>> h;
|
||||||
|
for (auto p : pointers) {
|
||||||
|
h.insert(p);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bench.run("Create and destroy Arena vector", [&]() {
|
||||||
|
Arena arena;
|
||||||
|
auto h = vector<void *>(arena);
|
||||||
|
for (auto p : pointers) {
|
||||||
|
h.push_back(p);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
{
|
||||||
|
Arena arena;
|
||||||
|
auto h = hashSet<void *>(arena);
|
||||||
|
bench.run("Find hashset", [&]() {
|
||||||
|
for (auto p : pointers) {
|
||||||
|
bench.doNotOptimizeAway(h.find(p));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
bench.run("Find vector", [&]() {
|
||||||
|
for (auto p : pointers) {
|
||||||
|
bench.doNotOptimizeAway(std::find(pointers.begin(), pointers.end(), p));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto p : pointers) {
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
// benchPointRead();
|
||||||
|
benchPointerSet();
|
||||||
|
}
|
@@ -43,7 +43,7 @@ struct Node {
|
|||||||
int16_t numChildren = 0;
|
int16_t numChildren = 0;
|
||||||
bool entryPresent = false;
|
bool entryPresent = false;
|
||||||
uint8_t parentsIndex = 0;
|
uint8_t parentsIndex = 0;
|
||||||
constexpr static auto kPartialKeyMaxLen = 10;
|
constexpr static auto kPartialKeyMaxLen = 26;
|
||||||
uint8_t partialKey[kPartialKeyMaxLen];
|
uint8_t partialKey[kPartialKeyMaxLen];
|
||||||
int8_t partialKeyLen = 0;
|
int8_t partialKeyLen = 0;
|
||||||
/* end section that's copied to the next node */
|
/* end section that's copied to the next node */
|
||||||
@@ -730,25 +730,37 @@ bool checkRangeRead(Node *n, const std::span<const uint8_t> begin,
|
|||||||
while (!left.step())
|
while (!left.step())
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rightDone) {
|
if (!rightDone) {
|
||||||
while (!right.step())
|
while (!right.step())
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
Arena arena;
|
Arena arena{64 << 10};
|
||||||
auto leftPath = vector<Node *>(arena);
|
// auto leftBorder = hashSet<Node *>(arena);
|
||||||
auto rightPath = vector<Node *>(arena);
|
// auto rightBorder = hashSet<Node *>(arena);
|
||||||
for (auto *iter = left.n; iter != nullptr; iter = iter->parent) {
|
auto leftBorder = vector<Node *>(arena);
|
||||||
leftPath.push_back(iter);
|
auto rightBorder = vector<Node *>(arena);
|
||||||
}
|
{
|
||||||
for (auto *iter = right.n; iter != nullptr; iter = iter->parent) {
|
auto *l = left.n;
|
||||||
rightPath.push_back(iter);
|
auto *r = right.n;
|
||||||
|
for (; l != nullptr && r != nullptr; l = l->parent, r = r->parent) {
|
||||||
|
leftBorder.push_back(l);
|
||||||
|
rightBorder.push_back(r);
|
||||||
|
}
|
||||||
|
for (; l != nullptr; l = l->parent) {
|
||||||
|
leftBorder.push_back(l);
|
||||||
|
}
|
||||||
|
for (; r != nullptr; r = r->parent) {
|
||||||
|
rightBorder.push_back(r);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG_VERBOSE && !defined(NDEBUG)
|
#if DEBUG_VERBOSE && !defined(NDEBUG)
|
||||||
fprintf(stderr, "firstGeq for `%s' got `%s'\n", printable(begin).c_str(),
|
fprintf(stderr, "firstGeq for `%s' got `%s'\n", printable(begin).c_str(),
|
||||||
getSearchPath(left.n).c_str());
|
getSearchPathPrintable(left.n).c_str());
|
||||||
fprintf(stderr, "firstGeq for `%s' got `%s'\n", printable(end).c_str(),
|
fprintf(stderr, "firstGeq for `%s' got `%s'\n", printable(end).c_str(),
|
||||||
getSearchPath(right.n).c_str());
|
getSearchPathPrintable(right.n).c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (left.n != nullptr && left.cmp != 0 &&
|
if (left.n != nullptr && left.cmp != 0 &&
|
||||||
@@ -764,12 +776,14 @@ bool checkRangeRead(Node *n, const std::span<const uint8_t> begin,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO better data structure for pointer set. Also collect during first
|
// TODO better data structure for pointer set. Also collect during first
|
||||||
// traversal.
|
// traversal?
|
||||||
for (auto *iter = nextPhysical(left.n); iter != right.n;) {
|
for (auto *iter = nextPhysical(left.n); iter != right.n;) {
|
||||||
const bool onLeftPath =
|
// const bool onLeftPath = leftBorder.find(iter) != leftBorder.end();
|
||||||
std::find(leftPath.begin(), leftPath.end(), iter) != leftPath.end();
|
// const bool onRightPath = rightBorder.find(iter) != rightBorder.end();
|
||||||
const bool onRightPath =
|
const bool onLeftPath = std::find(leftBorder.begin(), leftBorder.end(),
|
||||||
std::find(rightPath.begin(), rightPath.end(), iter) != rightPath.end();
|
iter) != leftBorder.end();
|
||||||
|
const bool onRightPath = std::find(rightBorder.begin(), rightBorder.end(),
|
||||||
|
iter) != rightBorder.end();
|
||||||
if (!onLeftPath && !onRightPath) {
|
if (!onLeftPath && !onRightPath) {
|
||||||
if (iter->maxVersion > readVersion) {
|
if (iter->maxVersion > readVersion) {
|
||||||
return false;
|
return false;
|
||||||
|
16
Internal.h
16
Internal.h
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <bit>
|
#include <bit>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -184,9 +185,20 @@ template <class T> using Set = std::set<T, std::less<T>, ArenaAlloc<T>>;
|
|||||||
template <class T> auto set(Arena &arena) {
|
template <class T> auto set(Arena &arena) {
|
||||||
return Set<T>(ArenaAlloc<T>(&arena));
|
return Set<T>(ArenaAlloc<T>(&arena));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T> struct MyHash;
|
||||||
|
|
||||||
|
template <class T> struct MyHash<T *> {
|
||||||
|
size_t operator()(const T *t) const noexcept {
|
||||||
|
size_t result;
|
||||||
|
memcpy(&result, &t, sizeof(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
using HashSet =
|
using HashSet =
|
||||||
std::unordered_set<T, std::hash<T>, std::equal_to<T>, ArenaAlloc<T>>;
|
std::unordered_set<T, MyHash<T>, std::equal_to<T>, ArenaAlloc<T>>;
|
||||||
template <class T> auto hashSet(Arena &arena) {
|
template <class T> auto hashSet(Arena &arena) {
|
||||||
return HashSet<T>(ArenaAlloc<T>(&arena));
|
return HashSet<T>(ArenaAlloc<T>(&arena));
|
||||||
}
|
}
|
||||||
@@ -449,7 +461,7 @@ template <class ConflictSetImpl> struct TestDriver {
|
|||||||
ConflictSetImpl cs{writeVersion};
|
ConflictSetImpl cs{writeVersion};
|
||||||
ReferenceImpl refImpl{writeVersion};
|
ReferenceImpl refImpl{writeVersion};
|
||||||
|
|
||||||
constexpr static auto kMaxKeyLen = 24;
|
constexpr static auto kMaxKeyLen = 32;
|
||||||
|
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user