-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack overflow #42
Comments
Thanks for the report! Sorry that I have no time debugging this currently. |
Not at all, thanks for all the free code :) Do you know of any resources on how to debug infinite recursion in nix? |
@jamii I tried looking at it for a few minutes, but I didn't get to the bottom. I think the best approach is to comment out dependencies until you have a minimal example that still doesn't evaluate, and then seeing if you can spot something that doesn't make sense. I still got the error after commenting out everything except |
|
I was wrong -
|
So you are saying the the dependent crates are even built multiple times? Then they are even multiple different derivations for them? (Otherwise the hashes should match and nix should build them only once)
Could you explain it in more detail for me? Thanks. |
@kolloch Each crate isn't built multiple times but it is evaluated multiple times, and the build only starts after the entire nix expression has been evaluated. I found discussion of a similar issue here: https://discourse.nixos.org/t/memoize-result-of-builtins-exec/2028 |
@kristoff3r is right, my language was imprecise. Functions like
Suppose we have a dependency tree like: A -> B1, B2 Without memoization, we'll construct the derivation for E 8 times - once for each path like A -> B1 -> C1 -> D1 -> E. Here are the number of times
|
Here is hacky way to memoize.
It cuts the instantiate time down to 3m43, which still seems pretty high. |
Even with this memoization, if I run with
|
@jamii I don't think memoization at that point in the code makes a difference. In fact, the last numbers are the same. We need to apply it at a lower level. |
Your explanation comment is just awesome, @jamii! Thank you for being so elaborate. |
I tried to memoize the feature resolution in https://github.com/kolloch/crate2nix/tree/cachedFeatureResolve Unfortunately, I get the following an error while compiling crate2nix. The weird thing is that I thought that I'd only change the feature resolution and the result of the feature resolution seems to be the same. I checked with nix eval --json '(let cargo = import crate2nix/Cargo.nix {}; in cargo.mergePackageFeatures { packageId = cargo.rootCrate.packageId; features = ["default"]; })' | nix run nixpkgs.jq -c jq It is also the same as the default resolution of nix eval --raw '(let cargo = import crate2nix/Cargo.nix {}; in cargo.diffDefaultPackageFeatures { packageId = cargo.rootCrate.packageId; })' | nix run nixpkgs.jq -c jq (it outputs some If you'd find the bug, I'd be very happy :) |
Memoization at that point reduced the runtime from 10m to 3m40 and the number of evaluations per package from several 100k to 1. I agree that the same problem seems to exist somewhere lower in the stack, but we probably need both. |
What was the error? |
Sure, we will memoize on both levels if that improves things :) I just looked at the last numbers of what you posted and they were the same? Probably missed something. The error is related to the log crate in env_logger. |
The first set of numbers was number of calls to buildByPackageId. That went down to 1 after memoization. The second set of numbers was package instantiations after memoization. I assume that they are the same number because at both levels the same graph is being unwound, so the number of paths is the same. But it seems to be two different parts of the code that are doing that same unwinding. |
BTW, why do you think that you memoization was hacky? I thought it was quite cool. Accidentially, I didn't know that this kind of forward reference is allowed in nix (buildRustCrate from builtRustCrate). Anyways, I also found the bug in the other memoization attempt. I am very curious if that improves things for you... |
Oh, just because I did the easiest thing that would test the hypothesis, rather than thinking about how best to write it.
It seems to be on par with memoizing buildByPackageId. The number of evaluations per package is sensible, but the number of instantiations is still huge. |
Using master (stable version had a missing ref in fetchGit):
--show-trace
doesn't show a trace.gdb shows:
nix
doesn't have debug symbols so I can't find the actual expr being run.I threw
builtins.trace
around in the tera file but nothing jumps out so far.Unfortunately I can't share the code, but here is the generated Cargo.nix - https://gist.github.com/jamii/5c347263b59292e2d9ae62baffc7685c
Without a proper stack trace I'm not sure how to go about debugging this.
The text was updated successfully, but these errors were encountered: