From a9b3d3d1c9e708ac67c4dde586d2f0c1d74c536f Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Thu, 14 Mar 2024 15:31:29 -0700 Subject: [PATCH] Show peak memory in skip list, and fix setOldestVersion bug It was not previously gc'ing faster than it was writing. --- SkipList.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/SkipList.cpp b/SkipList.cpp index 7c71a80..3d4e8ea 100644 --- a/SkipList.cpp +++ b/SkipList.cpp @@ -607,7 +607,7 @@ struct __attribute__((visibility("hidden"))) ConflictSet::Impl { values[i * 2 + 1] = w.end.len > 0 ? StringRef{w.end.p, size_t(w.end.len)} : keyAfter(arena, values[i * 2]); - keyUpdates += 2; + keyUpdates += 3; } skipList.find(values, fingers, temp, ss); skipList.addConflictRanges(fingers, ss / 2, writeVersion); @@ -621,14 +621,14 @@ struct __attribute__((visibility("hidden"))) ConflictSet::Impl { int temp; std::span key = removalKey; skipList.find(&key, &finger, &temp, 1); - skipList.removeBefore(oldestVersion, finger, std::exchange(keyUpdates, 0)); + skipList.removeBefore(oldestVersion, finger, std::exchange(keyUpdates, 10)); removalArena = Arena(); removalKey = copyToArena( removalArena, {finger.getValue().data(), finger.getValue().size()}); } private: - int64_t keyUpdates = 0; + int64_t keyUpdates = 10; Arena removalArena; std::span removalKey; int64_t oldestVersion; @@ -695,6 +695,13 @@ ConflictSet_create(int64_t oldestVersion) { __attribute__((__visibility__("default"))) void ConflictSet_destroy(void *cs) { using Impl = ConflictSet::Impl; ((Impl *)cs)->~Impl(); - free(cs); + safe_free(cs); } } + +struct __attribute__((visibility("default"))) PeakPrinter { + ~PeakPrinter() { + printf("malloc bytes: %g\n", double(mallocBytes)); + printf("Peak malloc bytes: %g\n", double(peakMallocBytes)); + } +} peakPrinter; \ No newline at end of file