Range reads are slow with dense keys
All checks were successful
Tests / Release [gcc] total: 363, passed: 363
GNU C Compiler (gcc) |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |0|0|0|0|:clap: Reference build: <a href="https://jenkins.weaselab.dev/job/weaselab/job/conflict-set/job/main/13//gcc">weaselab » conflict-set » main #13</a>
Tests / Coverage total: 361, passed: 361
weaselab/conflict-set/pipeline/head This commit looks good

This commit is contained in:
2024-02-12 15:46:56 -08:00
parent f8acc5ee86
commit d5bde56921
2 changed files with 26 additions and 22 deletions

View File

@@ -543,8 +543,8 @@ private:
};
struct SkipListConflictSet {
int64_t oldestVersion;
SkipListConflictSet(int64_t oldestVersion) : oldestVersion(oldestVersion) {}
SkipListConflictSet(int64_t oldestVersion)
: oldestVersion(oldestVersion), skipList(oldestVersion) {}
void check(const ConflictSet::ReadRange *reads, ConflictSet::Result *results,
int count) const {
Arena arena;
@@ -594,29 +594,37 @@ struct SkipListConflictSet {
}
private:
int64_t oldestVersion;
SkipList skipList;
};
} // namespace
constexpr int kNumKeys = 100000;
constexpr int kNumKeys = 1000000;
constexpr int kOpsPerTx = 100;
constexpr int kPrefixLen = 0;
std::span<const uint8_t> makeKey(Arena &arena, int index) {
auto result =
std::span<uint8_t>{new (arena) uint8_t[4 + kPrefixLen], 4 + kPrefixLen};
index = __builtin_bswap32(index);
memset(result.data(), 0, kPrefixLen);
memcpy(result.data() + kPrefixLen, &index, 4);
// auto result =
// std::span<uint8_t>{new (arena) uint8_t[32], 32};
// for (int i = 0; i < 32; ++i) {
// result[i] = index & (1 << (31 - i)) ? '1' : '0';
// }
return result;
}
template <class ConflictSet_> void benchConflictSet(const std::string &name) {
ankerl::nanobench::Bench bench;
bench.minEpochIterations(1000);
ConflictSet_ cs{0};
bench.batch(kOpsPerTx);
@@ -650,8 +658,6 @@ template <class ConflictSet_> void benchConflictSet(const std::string &name) {
};
auto points = set<std::span<const uint8_t>, Less>(arena);
// Two points for each range read, one for each point read, and one for each
// point write
while (points.size() < kOpsPerTx * 2 + 1) {
// TODO don't use rand?
points.insert(makeKey(arena, rand() % kNumKeys));
@@ -660,21 +666,21 @@ template <class ConflictSet_> void benchConflictSet(const std::string &name) {
// Make short-circuiting non-trivial
{
std::vector<ConflictSet::WriteRange> writes;
writes.reserve(kNumKeys);
for (int i = 0; i < kNumKeys; ++i) {
auto key = makeKey(arena, i);
if (points.find(key) != points.end()) {
continue;
}
ConflictSet::WriteRange conflict;
conflict.begin.p = key.data();
conflict.begin.len = key.size();
conflict.end.len = 0;
conflict.writeVersion = version + 1;
writes.push_back(conflict);
auto iter = points.begin();
++iter; // Complement of the set we'll be reading with range reads. Almost.
for (int i = 0; i < kOpsPerTx; ++i) {
auto begin = *iter++;
auto end = *iter++;
ConflictSet::WriteRange w;
w.begin.p = begin.data();
w.begin.len = begin.size();
w.end.p = end.data();
w.end.len = end.size();
w.writeVersion = version + 1;
writes.push_back(w);
}
cs.addWrites(writes.data(), writes.size());
++version;
cs.addWrites(writes.data(), kOpsPerTx);
}
{

View File

@@ -894,9 +894,7 @@ bytes:
bool checkRangeRead(Node *n, const std::span<const uint8_t> begin,
const std::span<const uint8_t> end, int64_t readVersion,
Arena &arena) {
auto left = FirstGeqStepwise{n, begin};
while (!left.step())
;
auto left = firstGeq(n, begin);
#if DEBUG_VERBOSE && !defined(NDEBUG)
fprintf(stderr, "firstGeq for `%s' got `%s'\n", printable(begin).c_str(),