!VRULIdgoKmKPzJZzjj:nixos.org

Nix Package Manager development

835 Members
For people hacking on Nix: https://github.com/NixOS/nix Nix maintainers can be reached here.179 Servers

Load older messages


SenderMessageTime
16 Aug 2025
@dramforever:matrix.orgdramforeveroops04:54:20
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)
In reply to @connorbaker:matrix.org
Sorry, I should have disambiguated -- Boehm GC
IFAIK there isn’t a lot of tooling for this. Boehm has some stuff to collect stats, but other than that I imagine you’d have to write custom tools for that.
06:57:23
@connorbaker:matrix.orgconnor (he/him) (UTC-7)I’ll post a small reproducer tomorrow of unexpected behavior I’m seeing with respect to the GC not freeing memory when I think it should be able to; I’d love to hear people’s thoughts on what could be causing it!06:59:36
@connorbaker:matrix.orgconnor (he/him) (UTC-7)Thank you for the PR shrinking the Value struct by the way, that was great!07:00:55
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)
In reply to @connorbaker:matrix.org
I’ll post a small reproducer tomorrow of unexpected behavior I’m seeing with respect to the GC not freeing memory when I think it should be able to; I’d love to hear people’s thoughts on what could be causing it!

That would be great to see. Honestly it’d be nice to actually hunker down and write the tooling that we need for GC debugging/visualization. Hit me up if you would like to work on that.

How’s the Immer thing going btw?

07:06:35
@joerg:thalheim.ioMic92
In reply to @fzakaria:one.ems.host
Also, CLion to debug live Nix has been amazing; unfortunately the GoogleTest integration doesn't work -- doesn't seem to hydrate the "Target"
Try raise(SIGTRAP); inside gtest
12:12:05
@joerg:thalheim.ioMic92Or this https://github.com/nemequ/portable-snippets/blob/master/debug-trap/debug-trap.h12:13:10
@connorbaker:matrix.orgconnor (he/him) (UTC-7)

I've got a file temp.nix with this expression:

let
  numClosures = 1;
  nixpkgsPath =
    (builtins.getFlake "github:NixOS/nixpkgs/42a63d6a63c0ae7d715e46450fe5a5f69394525d").outPath;
in
builtins.genList (
  _:
  let
    drvPath' = (import (nixpkgsPath + "/nixos/release.nix") { }).closures.gnome.x86_64-linux.drvPath;
  in
  builtins.deepSeq drvPath' drvPath'
) numClosures

I ran nix eval by way of

/usr/bin/env time -v env GC_INITIAL_HEAP_SIZE=512M GC_MAXIMUM_HEAP_SIZE=512M GC_PRINT_STATS=1 NIX_SHOW_STATS=1 nix eval --json --expr "$(cat temp.nix)"

and kept lowering the maximum GC size until it would OOM with a numClosures = 1 (that's how I arrived at 512M). My expectation is that 512M should be sufficient to evaluate many copies of that closure, given I'm taking only the drvPath, and the only increase in memory usage I'd expect between the first and second evaluation of the closure is that the evaluator has allocated memory for the list of derivations it's going to print as JSON. However, when I use numClosures = 2, I OOM. Keeping everything same, I bumped it up to 1G of memory, and I still OOM with numClosures = 2.

One thing which could be tested is to create a large expression in the same fashion, without using import, to see if that has a different memory profile.

19:01:26
@connorbaker:matrix.orgconnor (he/him) (UTC-7)

I would also like such tooling, but I really don't like reading or writing C/C++ :(

I've only ever read/written C/C++ in anger and I very much consider myself incompetent with C/C++

I haven't looked at or touched the Immer stuff in a long while; the biggest road blocks I saw to moving forward with it were:

  1. the issue where the GC would still collect values while they were needed
  2. creating wrappers around lists/bindings to abstract over the implementation (and the changes that would cause to the C API), although I think you did or started this with your Value refactoring
  3. rewriting relevant portions of the evaluator to use the different implementations offered by Immer (using the mutable APIs where appropriate)
  4. making changes to the stats reported by the Nix evaluator
  5. the lack of any sort of benchmark suite or platform on which to benchmark making it hard to discern what exactly changed and how

I think 1. was being looked at by the author of Immer, not sure whether they ever got the chance to get into it; 2. and 5. should happen regardless as a code/project hygiene thing.

Fundamentally I still think it's important we look at the data structures Nix offers, the ways in which those data structures are most commonly used, and implementations that make those operations fast :l

19:20:50
@magic_rb:matrix.redalder.orgmagic_rb Well going by how lambda calculus is evaluated in general. The import will be evaluated anew for each N. So what id try is wrapping the genList with a map seq to force evaluation of each thunk explicitly and see if that helps 19:32:44
@magic_rb:matrix.redalder.orgmagic_rbBut tbh i have no clue how nix evals, im going by how GHC does things, kinda. Just my first idea when i read your message19:34:27
@connorbaker:matrix.orgconnor (he/him) (UTC-7)There’s an import cache22:44:45
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)
In reply to @connorbaker:matrix.org
There’s an import cache
The import is cached, but the function call is not.
22:47:40
@connorbaker:matrix.orgconnor (he/him) (UTC-7)Also IIRC using JSON output forces everything22:52:32
@connorbaker:matrix.orgconnor (he/him) (UTC-7)Any ideas if the value storing the result of import applied to the path would be cached, or if the use of import is unrelated to what’s happening here, memory usage wise22:53:57
@emilazy:matrix.orgemily you're instantiating numClosures Nixpkgs and none of them are garbage 22:58:26
17 Aug 2025
@connorbaker:matrix.orgconnor (he/him) (UTC-7) It's my understanding that all of them should be garbage, because the only value retained from the instantiation is forced with deepSeq and should hold no references to that instantiation of Nixpkgs (though I suppose since it's a string with context it could hold references that way?). Put another way, is it possible there are still live references to those instances of Nixpkgs, or something about their instantiation is keeping them around? 05:21:43
@emilazy:matrix.orgemily hmm. maybe you are right. well, I don't think deepSeq is doing anything there since strings are atomic afaik 05:22:31
@emilazy:matrix.orgemilyso each thunk will keep around a reference until it is forced at least05:22:52
@emilazy:matrix.orgemilybut then the instantiation is in the thunk so… eh05:23:02
@roberthensing:matrix.orgRobert Hensing (roberth) deepSeq is not sufficient to drop all closures, as functions (lambdas) are normal form, but also have closures, much like thunks. You'd have to drop all functions (if any exist in your result, idk) 18:54:59
@emilazy:matrix.orgemily .drvPath shouldn't contain any functions I hope 18:55:58
@fzakaria:one.ems.hostfzakariaIt won't even run it though; using CLIon's gtest runner -- do you have it working?20:22:30
@fzakaria:one.ems.hostfzakariaI was looking today at https://github.com/jart/json.cpp -- vs nlohman20:23:42
@emilazy:matrix.orgemily the JSON library is extremely load-bearing for evaluation semantics, please don't switch it out without a very thorough test suite and fuzzing; the switch to nlohmann_json in 2.4 already produced a lot of eval changes 20:30:05
@fzakaria:one.ems.hostfzakariaJust sharing it; I sponsor jart via GitHub (I wish a larger amount) so I try to follow up on the work she does. -- I really like all the work she does + I find her code outstanding.20:32:43
@xokdvium:matrix.orgSergei Zimmerman (xokdvium)Also let's first handle the TOML fiasco20:40:26
@emilazy:matrix.orgemilyI did my best :D20:41:03
@fzakaria:one.ems.hostfzakariawas that solvable ? I thought it's just not because of the spec20:41:06
@emilazy:matrix.orgemilyit was solved by fixing the TOML spec violation in Nixpkgs20:41:30

Show newer messages


Back to Room ListRoom Version: 6