From 9fd7cf98dbec047343baefa65cd26ce4493bee53 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 22 May 2018 13:02:14 +0200 Subject: [PATCH] Memoise checkSourcePath() This prevents hydra-eval-jobs from statting the same files over and over again. --- src/libexpr/eval.cc | 8 +++++++- src/libexpr/eval.hh | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 353097f89..b2df14968 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -352,6 +352,10 @@ Path EvalState::checkSourcePath(const Path & path_) { if (!allowedPaths) return path_; + auto i = resolvedPaths.find(path_); + if (i != resolvedPaths.end()) + return i->second; + bool found = false; for (auto & i : *allowedPaths) { @@ -369,8 +373,10 @@ Path EvalState::checkSourcePath(const Path & path_) Path path = canonPath(path_, true); for (auto & i : *allowedPaths) { - if (isDirOrInDir(path, i)) + if (isDirOrInDir(path, i)) { + resolvedPaths[path_] = path; return path; + } } throw RestrictedPathError("access to path '%1%' is forbidden in restricted mode", path); diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 86e93a5ac..8594a2707 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -7,6 +7,7 @@ #include "hash.hh" #include +#include namespace nix { @@ -100,6 +101,9 @@ private: std::map> searchPathResolved; + /* Cache used by checkSourcePath(). */ + std::unordered_map resolvedPaths; + public: EvalState(const Strings & _searchPath, ref store);