Amortize cost of searching for continueKey
This commit is contained in:
@@ -801,7 +801,19 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
|
||||
|
||||
void printInOrderHelper(int64_t version, uint32_t node, int depth);
|
||||
|
||||
int accumulatedFuel = 0;
|
||||
|
||||
void scanAndRemoveOldEntries(int fuel) {
|
||||
accumulatedFuel += fuel;
|
||||
#ifdef NDEBUG
|
||||
// This is here for performance reasons, since we want to amortize the cost
|
||||
// of searching for continueKey. In tests, we want to exercise the rest of
|
||||
// the code often.
|
||||
if (accumulatedFuel < 500) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get a finger to the first entry > continueKey, or the last entry if
|
||||
// continueKey is the empty string
|
||||
if (latestRoot == 0) {
|
||||
@@ -838,7 +850,7 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
|
||||
|
||||
// Phew. Ok now we have a finger to the next entry to consider removing, and
|
||||
// the range version terminated at this entry.
|
||||
for (; fuel > 0; --fuel) {
|
||||
for (; accumulatedFuel > 0; --accumulatedFuel) {
|
||||
const auto &n = mm.base[finger.backNode()];
|
||||
if (rangeVersion < 0 && std::max(n.entry->pointVersion,
|
||||
n.entry->rangeVersion) < oldestVersion) {
|
||||
|
Reference in New Issue
Block a user