forked from lix-project/lix
* Big speedup (factor > 2.5) in all nix-env operations that do actual
instantiation, e.g. "nix-env -i" and "nix-env -qas" (but not "nix-env -qa"). It turns out that many redundant calls to addToStore(path) were made, which reads and hashes the entire path. For instance, the bash bootstrap binary in Nixpkgs would be read and hashed many times. As a result nix-env would spend around 92% of its time in the function sha256_block (according to callgrind). Some simple memoization fixes this.
This commit is contained in:
parent
6dca5c9099
commit
922697c8b2
|
@ -11,6 +11,10 @@
|
||||||
typedef map<Path, PathSet> DrvRoots;
|
typedef map<Path, PathSet> DrvRoots;
|
||||||
typedef map<Path, Hash> DrvHashes;
|
typedef map<Path, Hash> DrvHashes;
|
||||||
|
|
||||||
|
/* Cache for calls to addToStore(); maps source paths to the store
|
||||||
|
paths. */
|
||||||
|
typedef map<Path, Path> SrcToStore;
|
||||||
|
|
||||||
struct EvalState;
|
struct EvalState;
|
||||||
|
|
||||||
/* Note: using a ATermVector is safe here, since when we call a primop
|
/* Note: using a ATermVector is safe here, since when we call a primop
|
||||||
|
@ -24,6 +28,7 @@ struct EvalState
|
||||||
ATermMap primOps;
|
ATermMap primOps;
|
||||||
DrvRoots drvRoots;
|
DrvRoots drvRoots;
|
||||||
DrvHashes drvHashes; /* normalised derivation hashes */
|
DrvHashes drvHashes; /* normalised derivation hashes */
|
||||||
|
SrcToStore srcToStore;
|
||||||
Expr blackHole;
|
Expr blackHole;
|
||||||
|
|
||||||
unsigned int nrEvaluated;
|
unsigned int nrEvaluated;
|
||||||
|
|
|
@ -165,9 +165,15 @@ static void processBinding(EvalState & state, Expr e, Derivation & drv,
|
||||||
if (isDerivation(srcPath))
|
if (isDerivation(srcPath))
|
||||||
throw Error(format("file names are not allowed to end in `%1%'")
|
throw Error(format("file names are not allowed to end in `%1%'")
|
||||||
% drvExtension);
|
% drvExtension);
|
||||||
Path dstPath(addToStore(srcPath));
|
Path dstPath;
|
||||||
printMsg(lvlChatty, format("copied source `%1%' -> `%2%'")
|
if (state.srcToStore[srcPath] != "")
|
||||||
% srcPath % dstPath);
|
dstPath = state.srcToStore[srcPath];
|
||||||
|
else {
|
||||||
|
dstPath = addToStore(srcPath);
|
||||||
|
state.srcToStore[srcPath] = dstPath;
|
||||||
|
printMsg(lvlChatty, format("copied source `%1%' -> `%2%'")
|
||||||
|
% srcPath % dstPath);
|
||||||
|
}
|
||||||
drv.inputSrcs.insert(dstPath);
|
drv.inputSrcs.insert(dstPath);
|
||||||
ss.push_back(dstPath);
|
ss.push_back(dstPath);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue