Want to beta-test 33% memory improvement in Nix evaluations? Switch your NixOS and Nix configurations to use nixVersions.git
. This includes @xokdvium’s excellent work to reduce the memory impact of merging attrsets together. As of PR 444089, the attribute nixVersions.git
points to a pre-release of Nix 2.32.
Here’s a helpful snippet to measure the impact of this change (taken from Excessive memory use during eval of a particular flake - #4 by xokdvium):
$ NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=stats.json nix eval <ref> && jq '.gc.totalBytes' stats.json
Doing my own test, I saw my configuration evaluation drop from 3.7GiB to 2.4GiB. That’s an incredible change!
Is that compared to 2.31 or 2.28? There have been significant improvements in 2.30 as well.
Right I should have made it clear which version I compared against.
The first benchmark is from Lix 2.93.3. The second was from Nix 2.32pre20250919_07b96c1d.
Your comment does make me curious to try and benchmark from the 2.30 changes as well. I imagine the difference might not be as extreme.
How does it affect eval speed?
In my microbenchmarks the effect was pretty negligible. On the order of ~5% slower. But also keep in mind that the eval speed has improved significantly due to other optimisations, so 2.28 → 2.32 will have a positive effect on both eval times and memory usage.
Anecdotal results for evaluating my nixos configuration:
Benchmark 1 (3 runs): /nix/store/9gksyw4njp6xcq2k5xc6s181ssavbarw-nix-2.31.1/bin/nix eval .#nixosConfigurations.pc.config.system.build.toplevel --impure
measurement mean ± σ min … max delta
wall_time 11.5s ± 152ms 11.4s … 11.7s 0%
peak_rss 2.40GB ± 174KB 2.40GB … 2.40GB 0%
cpu_cycles 67.0G ± 540M 66.7G … 67.6G 0%
instructions 113G ± 22.8M 113G … 113G 0%
cache_references 3.74G ± 2.64M 3.73G … 3.74G 0%
cache_misses 582M ± 6.52M 577M … 590M 0%
branch_misses 395M ± 5.15M 389M … 399M 0%
Benchmark 2 (3 runs): /nix/store/ywf5siaq782x1a6i0h13wpf9hlnj4i00-nix-2.32pre20250919_07b96c1d/bin/nix eval .#nixosConfigurations.pc.config.system.build.toplevel --impure
measurement mean ± σ min … max delta
wall_time 11.8s ± 176ms 11.6s … 12.0s + 2.5% ± 3.2%
peak_rss 1.97GB ± 393KB 1.97GB … 1.97GB ⚡- 17.9% ± 0.0%
cpu_cycles 67.6G ± 514M 67.1G … 68.1G + 1.0% ± 1.8%
instructions 125G ± 5.52M 125G … 125G 💩+ 10.5% ± 0.0%
cache_references 3.60G ± 32.7M 3.57G … 3.63G ⚡- 3.7% ± 1.4%
cache_misses 596M ± 14.9M 582M … 612M + 2.4% ± 4.5%
branch_misses 419M ± 11.6M 407M … 430M + 6.0% ± 5.2%
Edit:
benchmark against 2.28:
Benchmark 1 (3 runs): /nix/store/5xc03pqk27736rppg305brbysdzqp37w-nix-2.28.5/bin/nix eval .#nixosConfigurations.pc.config.system.build.toplevel --impure
measurement mean ± σ min … max delta
wall_time 18.8s ± 7.25s 14.5s … 27.1s 0%
peak_rss 3.07GB ± 1.08MB 3.07GB … 3.07GB 0%
cpu_cycles 59.6G ± 4.06G 56.8G … 64.2G 0%
instructions 106G ± 9.67G 100G … 117G 0%
cache_references 3.98G ± 330M 3.79G … 4.36G 0%
cache_misses 635M ± 19.2M 618M … 656M 0%
branch_misses 404M ± 38.4M 378M … 448M 0%
Benchmark 2 (3 runs): /nix/store/ywf5siaq782x1a6i0h13wpf9hlnj4i00-nix-2.32pre20250919_07b96c1d/bin/nix eval .#nixosConfigurations.pc.config.system.build.toplevel --impure
measurement mean ± σ min … max delta
wall_time 12.1s ± 93.4ms 12.0s … 12.2s - 35.4% ± 62.0%
peak_rss 1.97GB ± 257KB 1.97GB … 1.97GB ⚡- 35.8% ± 0.1%
cpu_cycles 68.7G ± 485M 68.1G … 69.0G 💩+ 15.3% ± 11.0%
instructions 125G ± 11.1M 125G … 125G 💩+ 17.6% ± 14.6%
cache_references 3.61G ± 17.3M 3.59G … 3.62G - 9.4% ± 13.3%
cache_misses 615M ± 13.1M 607M … 631M - 3.1% ± 5.9%
branch_misses 425M ± 3.69M 422M … 429M + 5.4% ± 15.3%
Compared to lix 2.93.3, nix git shows a 10% time reduction and 40% memory reduction in evaluating my config (based on the equivalent poop
benchmark). Good stuff!
Also seeing 1/3 as many .gc.totalBytes
with non-flakes setup vs nix 2.28 (although much smaller absolute numbers in both cases, I guess I have a boring setup :))
~/src/mine/nixnix master !3 ?2 46s 13:44:36
❯ NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=stats.json /nix/store/ywf5siaq782x1a6i0h13wpf9hlnj4i00-nix-2.32pre20250919_07b96c1d/bin/nix-instantiate ~/src/mine/nixnix -A lamorna.system.config.sy
stem.build.toplevel && jq '.gc.totalBytes' stats.json
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
/nix/store/1vqklbyrlvx2a7wlj3wfpvslxfbszam9-nixos-system-lamorna-25.05.809873.9a094440e02a.drv
957680720
~/src/mine/nixnix master !3 ?2 16s 13:45:15
❯ NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=stats.json nix-instantiate ~/src/mine/nixnix -A lamorna
.system.config.system.build.toplevel && jq '.gc.totalBytes' stats.json
warning: you did not specify '--add-root'; the result might be removed by the garbage collector
/nix/store/1vqklbyrlvx2a7wlj3wfpvslxfbszam9-nixos-system-lamorna-25.05.809873.9a094440e02a.drv
1483055504
That’s indeed quite an improvement. Here’s a similar drop in gc.totalBytes
I observed while evaluating a devShell across Nix versions:
nixos-25.05/nixVersions.nix_2_24 (2.4 GB)
NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=stats.json nix run github:nixos/nixpkgs/nixos-25.05#nixVersions.nix_2_24 -- eval github:nammayatri/nammayatri/965c83963fbc67b9841ff80cc1ac1a9fa51f3343#devShells.x86_64-linux.backend && nix run nixpkgs#jq -- '.gc.totalBytes' stats.json
«derivation /nix/store/pcp8bl7k5v4m45qi03d5xxy9r43ji5yv-ny-backend.drv»
2409899552
nixpkgs-unstable/nixVersions.nix_2_30 (1.98 GB)
NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=stats.json nix run github:nixos/nixpkgs/a1f79a1770d05af18111fbbe2a3ab2c42c0f6cd0#nixVersions.nix_2_30 -- eval github:nammayatri/nammayatri/965c83963fbc67b9841ff80cc1ac1a9fa51f3343#devShells.x86_64-linux.backend && nix run nixpkgs#jq -- '.gc.totalBytes’ stats.json
«derivation /nix/store/pcp8bl7k5v4m45qi03d5xxy9r43ji5yv-ny-backend.drv»
1984224560
nixpkgs-unstable/nixVersions.git (1.48 GB)
NIX_SHOW_STATS=1 NIX_SHOW_STATS_PATH=stats.json nix run github:nixos/nixpkgs/a1f79a1770d05af18111fbbe2a3ab2c42c0f6cd0#nixVersions.git -- eval github:nammayatri/nammayatri/965c83963fbc67b9841ff80cc1ac1a9fa51f3343#devShells.x86_64-linux.backend && nix run nixpkgs#jq -- '.gc.totalBytes' stats.json
«derivation /nix/store/pcp8bl7k5v4m45qi03d5xxy9r43ji5yv-ny-backend.drv»
1481219344
Nix 2.32.0 is now out with these changes. If you were beta testing, please update to nixVersions.latest
to upgrade.