diff options
| author | Dan Engelbrecht <[email protected]> | 2024-09-30 10:45:40 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-09-30 10:45:40 +0200 |
| commit | 9eacd3a8097d365bdb5815cb039578e946523da7 (patch) | |
| tree | 98fa0776d4cacdd743d4e385dd7fc835c8fa34d5 /src/zenstore/gc.cpp | |
| parent | 5.5.8-pre4 (diff) | |
| download | zen-9eacd3a8097d365bdb5815cb039578e946523da7.tar.xz zen-9eacd3a8097d365bdb5815cb039578e946523da7.zip | |
use alternate IoHash comparision function (#177)v5.5.8-pre5
* Use alternate IoHash comparision function - reduces KeepUnusedReferences execution time by ~20%
Diffstat (limited to 'src/zenstore/gc.cpp')
| -rw-r--r-- | src/zenstore/gc.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/zenstore/gc.cpp b/src/zenstore/gc.cpp index 159b13af0..3e0dc5e04 100644 --- a/src/zenstore/gc.cpp +++ b/src/zenstore/gc.cpp @@ -593,6 +593,24 @@ Sum(GcResult& Stat, bool Cancelled = false) return Stat; } +// For GC the has order only needs to be predictable, it does not have to be "true" sort order +static inline bool +LessForGC(const IoHash& Lhs, const IoHash& Rhs) +{ + const uint32_t* LhsData = reinterpret_cast<const uint32_t*>(Lhs.Hash); + const uint32_t* RhsData = reinterpret_cast<const uint32_t*>(Rhs.Hash); + + return LhsData[0] < RhsData[0] ? true + : LhsData[0] != RhsData[0] ? false + : LhsData[1] < RhsData[1] ? true + : LhsData[1] != RhsData[1] ? false + : LhsData[2] < RhsData[2] ? true + : LhsData[2] != RhsData[2] ? false + : LhsData[3] < RhsData[3] ? true + : LhsData[3] != RhsData[3] ? false + : LhsData[4] < RhsData[4]; +} + bool FilterReferences(GcCtx& Ctx, std::string_view Context, std::vector<IoHash>& InOutReferences) { @@ -631,7 +649,7 @@ FilterReferences(GcCtx& Ctx, std::string_view Context, std::vector<IoHash>& InOu { return false; } - std::sort(InOutReferences.begin(), InOutReferences.end()); + std::sort(InOutReferences.begin(), InOutReferences.end(), LessForGC); auto NewEnd = std::unique(InOutReferences.begin(), InOutReferences.end()); InOutReferences.erase(NewEnd, InOutReferences.end()); return true; @@ -666,7 +684,7 @@ KeepUnusedReferences(std::span<const IoHash> SortedUsedReferences, std::span<IoH ReferencesRead++; UsedReferencesRead++; } - else if (Reference < UsedReference) + else if (LessForGC(Reference, UsedReference)) { // Keep it if (ReferencesRead > ReferencesWrite) @@ -3017,9 +3035,10 @@ TEST_CASE("scrub.basic") TEST_CASE("gc.keepunusedreferences") { - const IoHash Hashes[] = {IoHash::FromHexString("177030568fdd461bf4fe5ddbf4d463e514e8178e"), + // Order is important, this is the order the hashes would be sorted by FilterReferences + const IoHash Hashes[] = {IoHash::FromHexString("75ab3917854bfef7e72d795bb907a15cab1af2c3"), + IoHash::FromHexString("177030568fdd461bf4fe5ddbf4d463e514e8178e"), IoHash::FromHexString("372d795bb907a15cab15ab3917854bfef7e7af2c"), - IoHash::FromHexString("75ab3917854bfef7e72d795bb907a15cab1af2c3"), IoHash::FromHexString("ab3917854bfef7e7af2c372d795bb907a15cab15"), IoHash::FromHexString("d1df59fcab06793a5f2c372d795bb907a15cab15")}; { |