Skip to content

Commit d58453f

Browse files
committed
gc: don't visit implicit referrers on garbage collection
Before the change garbage collector was not considering `.drv` and outputs as alive even if configuration says otherwise. As a result `nix store gc --dry-run` could visit (and parse) `.drv` files multiple times (worst case it's quadratic). It happens because `alive` set was populating only runtime closure without regard for actual configuration. The change fixes it. Benchmark: my system has about 139MB, 40K `.drv` files. Performance before the change: $ time nix store gc --dry-run real 4m22,148s Performance after the change: $ time nix store gc --dry-run real 0m14,178s
1 parent a53c1dc commit d58453f

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/libstore/gc.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,8 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
678678
alive.insert(start);
679679
try {
680680
StorePathSet closure;
681-
computeFSClosure(*path, closure);
681+
computeFSClosure(*path, closure,
682+
/* flipDirection */ false, gcKeepOutputs, gcKeepDerivations);
682683
for (auto & p : closure)
683684
alive.insert(p);
684685
} catch (InvalidPath &) { }

0 commit comments

Comments
 (0)