Track evaluation performance
It'd be great to have a project with a lot of modules which we can use as a baseline for tracking performance, ideally by adding upper bounds on the number of operations reported by NIX_SHOW_STATS=1 and NIX_COUNT_CALLS=1.
CC @edolstra @cleverca22
I think I am probably running into something related to the thinking behind this.
I have a large project with several executables that use more or less of the project dependencies and modules. E.g. 15 "distinct" imports in one, 30 in another, many more in another.
I am able to get the snack example to work with the lightest such bin/Foo.hs, albeit with a long startup time:
time snack run
hi
real 0m8.762s
user 0m8.598s
sys 0m0.236s
(This overhead is the same every time.)
But with the larger ones, nix-build appears to just spend forever (I've left it running for hours) at 100% CPU (1 core).
Unfortunately, I'm not able to share the project (yet). So far, this is what I was able to gather:
If I add -v's to the nix-build command
nix-build -v -v -v -v -v - --no-out-link --max-jobs auto --argstr specJson {"sha256":"16nryjvfaw2dq55yp34hcw5bz8nlidhdi3yvr2ilr7lrlm4k54p1","url":"https://github.com/NixOS/nixpkgs-channels/archive/46d3867a08a9206685e2b6a8e19f5ad9f6ab4b39.tar.gz"} --argstr lib64 'H4sIANx1u1wAA+w8.........' --arg packageFile /home/patrick/project/package-snack.nix
I see
evaluating file '/nix/store/hbhdjn5ik3byg642d1m11k3k3s0kn3py-nix-2.2.2/share/nix/corepkgs/derivation.nix'
(i.e. it seems to be evaluating the expression forever).
I exported NIX_SHOW_STATS=1 and NIX_COUNT_CALLS=1 and got this output from the one that works: https://gist.github.com/patrickmn/91d165519626b33be8decfa2eaee655c
Unfortunately, the output from leaving the one that doesn't work after being left running for a while seems to be almost identical:
2c2
< "cpuTime": 0.16739,
---
> "cpuTime": 0.13266,
2503c2503
< "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/tools/compression/xz/default.nix",
---
> "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/tools/system/which/default.nix",
2506c2506
< "count": 2
---
> "count": 1
2510c2510
< "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/tools/compression/bzip2/default.nix",
---
> "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/tools/compression/xz/default.nix",
2513c2513
< "count": 1
---
> "count": 2
2531,2532c2531,2532
< "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/tools/system/which/default.nix",
< "line": 1,
---
> "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/development/tools/misc/texinfo/common.nix",
> "line": 3,
2538c2538
< "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/tools/compression/gzip/default.nix",
---
> "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/development/tools/misc/texinfo/common.nix",
2545,2547c2545,2547
< "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/development/tools/misc/texinfo/common.nix",
< "line": 3,
< "column": 1,
---
> "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/tools/compression/bzip2/default.nix",
> "line": 13,
> "column": 8,
2552c2552
< "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/development/tools/misc/texinfo/common.nix",
---
> "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/tools/compression/gzip/default.nix",
2560,2561c2560,2561
< "line": 13,
< "column": 8,
---
> "line": 1,
> "column": 1,
2587,2593d2586
< "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/development/tools/build-managers/gnumake/4.2/default.nix",
< "line": 1,
< "column": 1,
< "count": 1
< },
< {
< "name": null,
2601c2594
< "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/stdenv/common-path.nix",
---
> "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/development/tools/build-managers/gnumake/4.2/default.nix",
2677,2680c2670,2673
< "name": "inferBuild",
< "file": "/nix/store/5hdxji5ymgcn1fjk4ylcbhhgjaimqn9i-snack-lib/default.nix",
< "line": 59,
< "column": 16,
---
> "name": null,
> "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/development/perl-modules/generic/default.nix",
> "line": 1,
> "column": 1,
2685c2678
< "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/development/perl-modules/generic/default.nix",
---
> "file": "/nix/store/771b8qba444nnjbchc1app8m6f5mmd2v-source/pkgs/stdenv/common-path.nix",
2693a2687,2693
> "column": 16,
> "count": 1
> },
> {
> "name": "inferBuild",
> "file": "/nix/store/5hdxji5ymgcn1fjk4ylcbhhgjaimqn9i-snack-lib/default.nix",
> "line": 59,
Happy to provide more info in private. Would love to use snack as the build tool if possible.
Hey @patrickmn , could you give this branch a try? If you use niv should be as simple as niv update snack -b nm-fast.
It should fix some of the terrible asymptotic behavior when discovering modules. I still need to fix some similar behavior during the package spec parsing, but this shouldn't be a problem in your case.
Feel free to reach out to nicolas at nmattia.com if you need any more help and/or for feedback on the branch!
If the performance issue is present with large files and you are turning them into characters via (https://github.com/nmattia/snack/blob/2c490a259a7670192744021fb87bf7e430a4e7f0/snack-lib/files.nix#L25) then I'm pretty sure the issue is with coerceToString needing to count the length. I'm tracking this here: https://github.com/NixOS/nix/issues/9034