mirror of
https://github.com/NixOS/nix.git
synced 2025-11-15 06:52:43 +01:00
Add memoise primop
'builtins.memoise f x' is equal to 'f x', but uses a cache to speed up
repeated invocations of 'f' with the same 'x'. A typical application
is memoising evaluations of Nixpkgs in NixOps network
specifications. For example, with the patch below, the time to
evaluate a 10-machine NixOps network is reduced from 17.1s to 9.6s,
while memory consumption goes from 4486 MiB to 3089 MiB. (This is with
GC_INITIAL_HEAP_SIZE=16G.)
Nixpkgs patch:
diff --git a/pkgs/top-level/impure.nix b/pkgs/top-level/impure.nix
index a9f21e45aed..f641067e022 100644
--- a/pkgs/top-level/impure.nix
+++ b/pkgs/top-level/impure.nix
@@ -79,7 +79,7 @@ in
# not be passed.
assert args ? localSystem -> !(args ? system || args ? platform);
-import ./. (builtins.removeAttrs args [ "system" "platform" ] // {
+builtins.memoise or (x: x) (import ./.) (builtins.removeAttrs args [ "system" "platform" ] // {
inherit config overlays crossSystem;
# Fallback: Assume we are building packages on the current (build, in GNU
# Autotools parlance) system.
This commit is contained in:
parent
435ccc7980
commit
0395b9b94a
3 changed files with 116 additions and 1 deletions
|
|
@ -1683,6 +1683,8 @@ void EvalState::printStats()
|
|||
printMsg(v, format(" number of primop calls: %1%") % nrPrimOpCalls);
|
||||
printMsg(v, format(" number of function calls: %1%") % nrFunctionCalls);
|
||||
printMsg(v, format(" total allocations: %1% bytes") % (bEnvs + bLists + bValues + bAttrsets));
|
||||
printMsg(v, format(" memoisation hits: %d") % nrMemoiseHits);
|
||||
printMsg(v, format(" memoisation misses: %d") % nrMemoiseMisses);
|
||||
|
||||
#if HAVE_BOEHMGC
|
||||
GC_word heapSize, totalBytes;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue