diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-01-29 21:10:27 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-01-29 21:10:27 +0100 |
commit | 68e0ca608fa55d209a9d9c3b74a987ab496e0284 (patch) | |
tree | 693290d8a05112ca6605ef522acbe5b0a013e422 | |
parent | 26f895a26d37ec6049628fa835e20dfae5eb94dd (diff) |
Revive the flake cache
Not that it matters a lot anymore - we respect lock files of inputs
now, so we're doing a lot fewer flake lookups.
-rw-r--r-- | src/libexpr/flake/flake.cc | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index adcb88dcc..f255f99e2 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -31,22 +31,20 @@ static FlakeRef maybeLookupFlake( return flakeRef; } -typedef std::vector<std::pair<FlakeRef, FlakeRef>> RefMap; +typedef std::vector<std::pair<FlakeRef, FlakeRef>> FlakeCache; -static FlakeRef lookupInRefMap( - const RefMap & refMap, +static FlakeRef lookupInFlakeCache( + const FlakeCache & flakeCache, const FlakeRef & flakeRef) { -#if 0 // FIXME: inefficient. - for (auto & i : refMap) { - if (flakeRef.contains(i.first)) { + for (auto & i : flakeCache) { + if (flakeRef == i.first) { debug("mapping '%s' to previously seen input '%s' -> '%s", flakeRef, i.first, i.second); return i.second; } } -#endif return flakeRef; } @@ -122,11 +120,11 @@ static std::map<FlakeId, FlakeInput> parseFlakeInputs( } static Flake getFlake(EvalState & state, const FlakeRef & originalRef, - bool allowLookup, RefMap & refMap) + bool allowLookup, FlakeCache & flakeCache) { - auto flakeRef = lookupInRefMap(refMap, + auto flakeRef = lookupInFlakeCache(flakeCache, maybeLookupFlake(state, - lookupInRefMap(refMap, originalRef), allowLookup)); + lookupInFlakeCache(flakeCache, originalRef), allowLookup)); auto [sourceInfo, resolvedInput] = flakeRef.input->fetchTree(state.store); @@ -135,8 +133,8 @@ static Flake getFlake(EvalState & state, const FlakeRef & originalRef, debug("got flake source '%s' from '%s'", state.store->printStorePath(sourceInfo.storePath), resolvedRef); - refMap.push_back({originalRef, resolvedRef}); - refMap.push_back({flakeRef, resolvedRef}); + flakeCache.push_back({originalRef, resolvedRef}); + flakeCache.push_back({flakeRef, resolvedRef}); if (state.allowedPaths) state.allowedPaths->insert(sourceInfo.actualPath); @@ -221,19 +219,19 @@ static Flake getFlake(EvalState & state, const FlakeRef & originalRef, Flake getFlake(EvalState & state, const FlakeRef & originalRef, bool allowLookup) { - RefMap refMap; - return getFlake(state, originalRef, allowLookup, refMap); + FlakeCache flakeCache; + return getFlake(state, originalRef, allowLookup, flakeCache); } static std::pair<fetchers::Tree, FlakeRef> getNonFlake( EvalState & state, const FlakeRef & originalRef, bool allowLookup, - RefMap & refMap) + FlakeCache & flakeCache) { - auto flakeRef = lookupInRefMap(refMap, + auto flakeRef = lookupInFlakeCache(flakeCache, maybeLookupFlake(state, - lookupInRefMap(refMap, originalRef), allowLookup)); + lookupInFlakeCache(flakeCache, originalRef), allowLookup)); auto [sourceInfo, resolvedInput] = flakeRef.input->fetchTree(state.store); @@ -242,8 +240,8 @@ static std::pair<fetchers::Tree, FlakeRef> getNonFlake( debug("got non-flake source '%s' from '%s'", state.store->printStorePath(sourceInfo.storePath), resolvedRef); - refMap.push_back({originalRef, resolvedRef}); - refMap.push_back({flakeRef, resolvedRef}); + flakeCache.push_back({originalRef, resolvedRef}); + flakeCache.push_back({flakeRef, resolvedRef}); if (state.allowedPaths) state.allowedPaths->insert(sourceInfo.actualPath); @@ -304,9 +302,9 @@ LockedFlake lockFlake( { settings.requireExperimentalFeature("flakes"); - RefMap refMap; + FlakeCache flakeCache; - auto flake = getFlake(state, topRef, lockFlags.useRegistries, refMap); + auto flake = getFlake(state, topRef, lockFlags.useRegistries, flakeCache); LockFile oldLockFile; @@ -428,7 +426,7 @@ LockedFlake lockFlake( if (input.isFlake) { auto inputFlake = getFlake(state, input.ref, - lockFlags.useRegistries, refMap); + lockFlags.useRegistries, flakeCache); newLocks.inputs.insert_or_assign(id, LockedInput(inputFlake.resolvedRef, inputFlake.originalRef, inputFlake.sourceInfo->narHash)); @@ -448,7 +446,7 @@ LockedFlake lockFlake( else { auto [sourceInfo, resolvedRef] = getNonFlake(state, input.ref, - lockFlags.useRegistries, refMap); + lockFlags.useRegistries, flakeCache); newLocks.inputs.insert_or_assign(id, LockedInput(resolvedRef, input.ref, sourceInfo.narHash)); } @@ -563,8 +561,8 @@ static void prim_callFlake(EvalState & state, const Pos & pos, Value * * args, V callFlake(state, flake, lazyInput->lockedInput, v); } else { - RefMap refMap; - auto [sourceInfo, resolvedRef] = getNonFlake(state, lazyInput->lockedInput.ref, false, refMap); + FlakeCache flakeCache; + auto [sourceInfo, resolvedRef] = getNonFlake(state, lazyInput->lockedInput.ref, false, flakeCache); if (sourceInfo.narHash != lazyInput->lockedInput.narHash) throw Error("the content hash of repository '%s' doesn't match the hash recorded in the referring lockfile", |