Skip to content

[perf] in syncPackagesToProfile, only removeExtraItemsFromProfile is mode is not install #1541

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 4 commits into from
Oct 11, 2023

Conversation

savil
Copy link
Collaborator

@savil savil commented Oct 7, 2023

Summary

Doing devbox global add <package> was taking 9 seconds for me. Most of this time
was spent in removeExtraPackagesFromProfile. This operation takes longer
because it calls devpkg.NormalizedPackageAttributePath which calls nix.Search
which is slow.

Instead, I advocate for us to not do this step when adding packages.

How was it tested?

devbox global add <package> is now snappy

Copy link
Collaborator Author

savil commented Oct 7, 2023

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.

What if we reintroduce the heuristic where we only remove extra packages if the counts don't match. Or better yet, only if profile has more than devbox.json

@savil
Copy link
Collaborator Author

savil commented Oct 7, 2023

🤔 I think but need to verify that'll break the update scenario where the same package needs to be removed and added from profile

@savil
Copy link
Collaborator Author

savil commented Oct 9, 2023

@mikeland73 looking at this again, I do think the update scenario where the "resolved" store-path of the package has changed will not work if we apply the heuristic.

The old heuristic only worked b/c we did add-then-remove, but we now do remove-then-add:

if len(packages) == len(profileItems) {
	// Optimization: skip comparison if number of packages are the same. This only works
	// because we assume that all packages in `devbox.json` have just been added to the
	// profile.
	return nil, nil
}

Strictly speaking this also affected the update scenario, but it depends on which store-path got higher priority...

I think skipping removeExtraPackages for install is okay. We already skip addPackages for uninstall.

That said, I want to make this faster for ensure mode. In particular, I'm thinking we could have a local file cache map of "resolved-nixpkgs-commit-hash" to "NormalizedPackageAttributePath". IIUC this doesn't change and is a one-time calculation for that specific particular resolution of the nix package. EDIT: see #1546

@savil savil requested a review from mikeland73 October 9, 2023 18:42
@savil savil force-pushed the savil/print-dev-env-less-for-add-rm branch from 6ca1aea to 52c491b Compare October 10, 2023 18:01
@savil savil force-pushed the savil/skip-remove-extra-if-install branch from 9df671e to d780346 Compare October 10, 2023 18:01
@savil savil force-pushed the savil/print-dev-env-less-for-add-rm branch from 52c491b to 85a4b9a Compare October 10, 2023 18:04
@savil savil force-pushed the savil/skip-remove-extra-if-install branch from d780346 to 538363b Compare October 10, 2023 18:04
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.

@savil do you think this is still needed after #1546 ?

This is OK (which is why I'm approving) but it has 2 downsides:

  • We no longer fully sync packages on add so if a package is removed manually from devbox.json this won't remove it from profile on add.
  • This adds complexity depending on mode which makes ensure and sync harder to reason about.

If after landing #1546 this is still an improvement, lets go for it. But my impression is that removeExtraItemsFromProfile is probably slow due to search.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

remove

@savil savil force-pushed the savil/print-dev-env-less-for-add-rm branch from 85a4b9a to 609f2bc Compare October 11, 2023 12:54
@savil savil force-pushed the savil/skip-remove-extra-if-install branch from 538363b to da47197 Compare October 11, 2023 12:54
@savil
Copy link
Collaborator Author

savil commented Oct 11, 2023

Likely not needed as much. I agree it adds some complexity so avoidable. That said, the complexity is already there for uninstall. Will keep it in abeyance.

Base automatically changed from savil/print-dev-env-less-for-add-rm to main October 11, 2023 13:12
@savil
Copy link
Collaborator Author

savil commented Oct 11, 2023

Since #1546 needs more work and/or exploration, I'm going to land this.

The scenario of a package being added manually in devbox.json, but then not being added via devbox add is fairly remote, and I think we can live with it until the next release. Once #1546 or its successor lands, then we can remove the special-casing we have for install and uninstall skipping work in this syncPackagesToProfile.

@savil savil merged commit d2b5be5 into main Oct 11, 2023
@savil savil deleted the savil/skip-remove-extra-if-install branch October 11, 2023 16:02
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