Skip to content

[perf] FillNarInfoCache during nix profile's pendingPackagesForInstallation #1528

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

Merged
merged 1 commit into from
Oct 4, 2023

Conversation

savil
Copy link
Collaborator

@savil savil commented Oct 3, 2023

Summary

@Lagoja has a healthy number of devbox global packages. This exposed that devbox add <package> had a perf regression for him:

❯ devbox global add procs

Exec times over 1ms:
"ensurePackagesAreInstalled" took 1.44075ms
"nixEnv" took 2.446083ms
"devbox shellenv --preserve-path-stack -c /Users/johnlago/.local/share/devbox/global/default" took 49.446834ms

Exec times over 1ms:
"devbox shellenv only-path-without-wrappers" took 45.889ms

Installing package: procs@latest.

[1/1] procs@latest
[1/1] procs@latest: Success

Exec times over 1ms:
"syncPackagesToProfile" took 31.80875375s
Recomputing the devbox environment.
"CreateWrappers" took 17.186833ms
"ensurePackagesAreInstalled" took 36.056620833s
"devbox global add procs" took 36.410408875s

See the syncPackagesToProfile taking 31 seconds!

After re-running with --trace, he got the trace.out file at: https://gist.github.com/savil/f6abd6a3adc8e7c92d1d3fd9ecbb93d7

Opening with go tool trace -http=localhost:6060 trace.out shows:
Screenshot 2023-10-03 at 5 14 05 PM

This reveals that we're doing 15 seconds of http requests.

The new codepath does a HEAD request to verify that the binary is still cached in the nix binary cache. The problem is that it does it serially in a for-loop for each package.

Fix
We have a function FillNarInfoCache that spawns goroutines to do it concurrently. This should speed up the time.

How was it tested?

I was able to do devbox global add procs as a sanity check.

Copy link
Collaborator Author

savil commented Oct 3, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@savil savil requested a review from mikeland73 October 4, 2023 00:16
@savil savil marked this pull request as ready for review October 4, 2023 00:19
Copy link
Contributor

@mikeland73 mikeland73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't hurt, but is it correct pendingPackagesForInstallation checks all packages when you are only trying to install one of them? That feels weird and it means we're gonna make many more http requests (even if they are in parallel) every time.

@savil
Copy link
Collaborator Author

savil commented Oct 4, 2023

pendingPackagesForInstallation runs in many different contexts, not just adding packages. Its job is to ensure the nix profile matches the devbox.json, and so it needs to check which of the packages are remaining to be added.

@savil
Copy link
Collaborator Author

savil commented Oct 4, 2023

I think we can be smarter about when to check for the HEAD request (have some ideas). Will investigate more...

@savil savil merged commit a3bac39 into main Oct 4, 2023
@savil savil deleted the savil/pending-profile-packages-perf branch October 4, 2023 04:27
@savil
Copy link
Collaborator Author

savil commented Oct 4, 2023

I also think merging addPackagesToProfile and tidyProfile would be beneficial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants