Skip to content

Commit

Permalink
* checkVarDefs: don't check in closed terms, which don't have
Browse files Browse the repository at this point in the history
  undefined variables by definition.  This matters for the
  implementation of "with", which does a call to checkVarDefs to see
  if the body of the with has no undefined variables.  (It can't be
  checked at parse time because you don't know which variables are in
  the "with" attribute set.)  If we check closed terms, then we check
  not just the with body but also the substituted terms, which are
  typically very large.  This is the cause of the poor nix-env
  performance on Nixpkgs lately.  It didn't happen earlier because
  "with" wasn't used very often in the past.

  This fix improves nix-env performance roughly 60x on current Nixpkgs.
  nix-env -qa is down from 29.3s to 0.5s on my laptop, and nix-env -qa
  --out-path is down from 229s to 3.39s.  Not bad for a 1-line fix :-)
  • Loading branch information
edolstra committed Feb 21, 2008
1 parent 0ed89c5 commit 0a84137
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libexpr/nixexpr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,11 @@ static void checkVarDefs2(set<Expr> & done, const ATermMap & defs, Expr e)
ATerm with, body;
ATermList rbnds, nrbnds;

if (matchVar(e, name)) {
/* Closed terms don't have free variables, so we don't have to
check by definition. */
if (matchClosed(e, value)) return;

else if (matchVar(e, name)) {
if (!defs.get(name))
throw EvalError(format("undefined variable `%1%'")
% aterm2String(name));
Expand Down

0 comments on commit 0a84137

Please sign in to comment.