Don't scan+apply every setOldestVersion call
This commit is contained in:
16
Bench.cpp
16
Bench.cpp
@@ -3,11 +3,11 @@
|
|||||||
#include <nanobench.h>
|
#include <nanobench.h>
|
||||||
|
|
||||||
void monotonicallyIncreasing() {
|
void monotonicallyIncreasing() {
|
||||||
constexpr int kWindow = 100;
|
constexpr int kWindow = 1000;
|
||||||
ankerl::nanobench::Bench bench;
|
ankerl::nanobench::Bench bench;
|
||||||
Facade facade{0};
|
Facade facade{0};
|
||||||
|
|
||||||
bench.minEpochIterations(1000);
|
bench.minEpochIterations(kWindow * 10);
|
||||||
|
|
||||||
bench.warmup(kWindow).run("monotonically increasing", [&] {
|
bench.warmup(kWindow).run("monotonically increasing", [&] {
|
||||||
const int64_t remove = __builtin_bswap64(facade.getVersion() - kWindow);
|
const int64_t remove = __builtin_bswap64(facade.getVersion() - kWindow);
|
||||||
@@ -29,18 +29,6 @@ void monotonicallyIncreasing() {
|
|||||||
const auto end = facade.versioned.end(v);
|
const auto end = facade.versioned.end(v);
|
||||||
auto iter = begin;
|
auto iter = begin;
|
||||||
|
|
||||||
bench.run("scan", [&] {
|
|
||||||
for (iter = begin; iter != end; ++iter) {
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
bench.run("reverse scan", [&] {
|
|
||||||
iter = end;
|
|
||||||
do {
|
|
||||||
--iter;
|
|
||||||
} while (iter != begin);
|
|
||||||
});
|
|
||||||
|
|
||||||
bench.run("deref", [&] { bench.doNotOptimizeAway(*iter); });
|
bench.run("deref", [&] { bench.doNotOptimizeAway(*iter); });
|
||||||
|
|
||||||
iter = begin;
|
iter = begin;
|
||||||
|
22
Facade.h
22
Facade.h
@@ -12,7 +12,8 @@ using String = std::basic_string<uint8_t>;
|
|||||||
struct Facade {
|
struct Facade {
|
||||||
|
|
||||||
explicit Facade(int64_t version)
|
explicit Facade(int64_t version)
|
||||||
: unversionedVersion(version), versioned{version} {}
|
: oldestVersion(version), nextPurgeVersion(version),
|
||||||
|
unversionedVersion(version), versioned(version) {}
|
||||||
|
|
||||||
struct View {
|
struct View {
|
||||||
|
|
||||||
@@ -131,6 +132,15 @@ struct Facade {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setOldestVersion(int64_t version) {
|
void setOldestVersion(int64_t version) {
|
||||||
|
// Don't scan and apply mutations every time setOldestVersion is called.
|
||||||
|
|
||||||
|
oldestVersion = version;
|
||||||
|
if (version >= nextPurgeVersion) {
|
||||||
|
nextPurgeVersion = versioned.getVersion();
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto iter = versioned.begin(version), end = versioned.end(version);
|
for (auto iter = versioned.begin(version), end = versioned.end(version);
|
||||||
iter != end; ++iter) {
|
iter != end; ++iter) {
|
||||||
auto m = *iter;
|
auto m = *iter;
|
||||||
@@ -162,10 +172,14 @@ struct Facade {
|
|||||||
versioned.setOldestVersion(version);
|
versioned.setOldestVersion(version);
|
||||||
}
|
}
|
||||||
|
|
||||||
View viewAt(int64_t version) const { return View{this, version}; }
|
View viewAt(int64_t version) const {
|
||||||
|
assert(version >= oldestVersion);
|
||||||
|
assert(version <= versioned.getVersion());
|
||||||
|
return View{this, version};
|
||||||
|
}
|
||||||
|
|
||||||
int64_t getVersion() const { return versioned.getVersion(); }
|
int64_t getVersion() const { return versioned.getVersion(); }
|
||||||
int64_t getOldestVersion() const { return versioned.getOldestVersion(); }
|
int64_t getOldestVersion() const { return oldestVersion; }
|
||||||
|
|
||||||
void unversionedRead(const String &begin, const String &end, int &limit,
|
void unversionedRead(const String &begin, const String &end, int &limit,
|
||||||
bool reverse,
|
bool reverse,
|
||||||
@@ -197,6 +211,8 @@ struct Facade {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t oldestVersion;
|
||||||
|
int64_t nextPurgeVersion;
|
||||||
int64_t unversionedVersion;
|
int64_t unversionedVersion;
|
||||||
std::map<String, String> unversioned;
|
std::map<String, String> unversioned;
|
||||||
weaselab::VersionedMap versioned;
|
weaselab::VersionedMap versioned;
|
||||||
|
Reference in New Issue
Block a user