aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libcmd/installables.cc23
-rw-r--r--src/libexpr/eval.hh9
2 files changed, 24 insertions, 8 deletions
diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc
index a10214561..711cf1b07 100644
--- a/src/libcmd/installables.cc
+++ b/src/libcmd/installables.cc
@@ -393,13 +393,10 @@ ref<eval_cache::EvalCache> openEvalCache(
EvalState & state,
std::shared_ptr<flake::LockedFlake> lockedFlake)
{
- auto fingerprint = lockedFlake->getFingerprint();
- return make_ref<nix::eval_cache::EvalCache>(
- evalSettings.useEvalCache && evalSettings.pureEval
- ? std::optional { std::cref(fingerprint) }
- : std::nullopt,
- state,
- [&state, lockedFlake]()
+ auto fingerprint = evalSettings.useEvalCache && evalSettings.pureEval
+ ? std::make_optional(lockedFlake->getFingerprint())
+ : std::nullopt;
+ auto rootLoader = [&state, lockedFlake]()
{
/* For testing whether the evaluation cache is
complete. */
@@ -415,7 +412,17 @@ ref<eval_cache::EvalCache> openEvalCache(
assert(aOutputs);
return aOutputs->value;
- });
+ };
+
+ if (fingerprint) {
+ auto search = state.evalCaches.find(fingerprint.value());
+ if (search == state.evalCaches.end()) {
+ search = state.evalCaches.emplace(fingerprint.value(), make_ref<nix::eval_cache::EvalCache>(fingerprint, state, rootLoader)).first;
+ }
+ return search->second;
+ } else {
+ return make_ref<nix::eval_cache::EvalCache>(std::nullopt, state, rootLoader);
+ }
}
Installables SourceExprCommand::parseInstallables(
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index ec6e2bb5e..8e390e46d 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -33,6 +33,10 @@ class EvalState;
class StorePath;
struct SingleDerivedPath;
enum RepairFlag : bool;
+struct MemoryInputAccessor;
+namespace eval_cache {
+ class EvalCache;
+}
/**
@@ -234,6 +238,11 @@ public:
return *new EvalErrorBuilder<T>(*this, args...);
}
+ /**
+ * A cache for evaluation caches, so as to reuse the same root value if possible
+ */
+ std::map<const Hash, ref<eval_cache::EvalCache>> evalCaches;
+
private:
/* Cache for calls to addToStore(); maps source paths to the store