aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/gc.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2021-10-15 12:20:23 +0200
committerEelco Dolstra <edolstra@gmail.com>2021-10-15 12:20:23 +0200
commit304180d0ded6bf166b051f2b2ce5c33c18c2bbfe (patch)
tree997408435a0ad761d5eba10c15549873e27a660d /src/libstore/gc.cc
parent17e6ebcc90b6c7d5db8588f1d2b914c98543560b (diff)
Memoize queryReferrers()
Diffstat (limited to 'src/libstore/gc.cc')
-rw-r--r--src/libstore/gc.cc14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index 03d44ebf8..ed792a777 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -617,6 +617,8 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
}
};
+ std::map<StorePath, StorePathSet> referrersCache;
+
/* Helper function that visits all paths reachable from `start`
via the referrers edges and optionally derivers and derivation
output edges. If none of those paths are roots, then all
@@ -689,9 +691,14 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
if (isValidPath(*path)) {
/* Visit the referrers of this path. */
- StorePathSet referrers;
- queryReferrers(*path, referrers);
- for (auto & p : referrers)
+ auto i = referrersCache.find(*path);
+ if (i == referrersCache.end()) {
+ StorePathSet referrers;
+ queryReferrers(*path, referrers);
+ referrersCache.emplace(*path, std::move(referrers));
+ i = referrersCache.find(*path);
+ }
+ for (auto & p : i->second)
enqueue(p);
/* If keep-derivations is set and this is a
@@ -718,6 +725,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
if (shouldDelete) {
invalidatePathChecked(path);
deleteFromStore(path.to_string());
+ referrersCache.erase(path);
}
}
};