tweag / nix-hour

Questions for the weekly Nix Hour
MIT License
78 stars 3 forks source link

What does 2023 Nix cache? #32

Closed t184256 closed 1 year ago

t184256 commented 1 year ago

"The Purely Functional Software Deployment Model" paper (4.4. Implementation @ pp. 81-83) paints a pretty rosy picture of the possibilities of evaluation-time caching:

Maximal sharing is extremely useful in the implementation of a Nix expression interpreter since it allows easy caching of evaluation results, which speeds up expression evaluation by removing unnecessary evaluation of identical terms. The interpreter maintains a hash lookup table cache : ATerm → ATerm that maps ATerms representing Nix expressions to their normal form.

The current evaluation cache never forgets the evaluation result of any term. This obviously does not scale very well, so one might want to clear or prune the cache eventually, possibly using a least-recently used (LRU) eviction scheme. However, the size of current Nix expressions (such as those produced during the evaluation of Nixpkgs) has not compelled me to implement cache pruning yet.

This probably hasn't aged well, has it? Nixpkgs has grown huge, evaluating it doesn't feel instant. In general: aside of remote store lookups, what does Nix cache these days? Does it keep and use a persistent evaluation cache? With flakes, what is being cached and what is not? Are dirty flakes always reevaluated?

infinisil commented 1 year ago

We looked at this in Nix Hour #38