-
Notifications
You must be signed in to change notification settings - Fork 86
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
Super-linear instantiation counts/time #90
Comments
Thanks for the report, especially the commands to reproduce. Note that you are not specifying an attribute path, I think, therefore that might try to build the same thing in multiple ways. But interestingly enough, adding it does not change the paths in my test case (with the Cargo.nix from crate2nix). I also don't know how much of this is expected. I'd expect that instantiations of the same drv are cheap but there seems to be at least an sqlite lookup for every instantiation which is wasteful. Within the FYI, I went with a slightly modified:
(which shows the top contenders first) |
I went ahead and made a flamegraph of nix when evaluating a further cut-down Cargo.toml. This suggests that most of the time is spent in build-rust-crate rather than the code generated by |
I don't have time right now but flamegraph did sound awesome! How did you create it? I want to play with that :) With "looks sketchy", you mean that it is a hot spot? Maybe we can optimize but maybe it is also just called too often. |
@kolloch https://github.com/NixOS/nix/blob/2.3.1/contrib/stack-collapse.py that is probably how that was generated. The comments at the top of that script explain how you get there. Just looking at the That whole block doesn't really seem to be required for any of the current users of Applying the following patch I was able to cut down the execution time and trace file size by a factor of roughly ten. diff --git a/pkgs/build-support/rust/build-rust-crate/default.nix b/pkgs/build-support/rust/build-rust-crate/default.nix
index 569b48d25ae..f3a18161127 100644
--- a/pkgs/build-support/rust/build-rust-crate/default.nix
+++ b/pkgs/build-support/rust/build-rust-crate/default.nix
@@ -63,7 +63,7 @@ let crate = crate_ // (lib.attrByPath [ crate_.crateName ] (attr: {}) crateOverr
buildTests_ = buildTests;
# take a list of crates that we depend on and override them to fit our overrides, rustc, release, …
- makeDependencies = map (dep: lib.getLib (dep.override { inherit release verbose crateOverrides; }));
+ makeDependencies = map (dep: lib.getLib dep);
# crate2nix has a hack for the old bash based build script that did split
# entries at `,`. No we have to work around that hack. I'll try to investigate where that line actually originates from and if it is really superfluous. |
Wow, I am excited, that sounds awesome @andir! |
@andir's fix got merged! I will close this for now but feel free to open another issue if you think that performance is still unacceptable. |
We have a fairly large workspace which in total pulls in approximately 900 dependencies IIRC. Running
nix-instantiate Cargo.nix
for that workspace takes minutes. Taking a look into it I found that it instantiates some crate derivations multiple times, sometimes tens of thousands of times!This issue can also be reproduced with smaller workspaces too! While it won’t take minutes to instantiate, you will still notice it being slow.
Reproducer
First, copy the following
Cargo.toml
file to somewhere:Then run
You should see something resembling the following output:
I have no idea where to even begin looking or what could cause nix to re-instantiate the same crate many many times. It could be an issue inherent to nix, but as I’m not sure whether it is, I’ve reported it here first.
cc @andir
The text was updated successfully, but these errors were encountered: