Skip to content

Commit

Permalink
[perf] in syncPackagesToProfile, only removeExtraItemsFromProfile is …
Browse files Browse the repository at this point in the history
…mode is not install (jetify-com#1541)

## 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
  • Loading branch information
savil authored Oct 11, 2023
1 parent b6d0b20 commit d2b5be5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Binary file added examples/development/go/hello-world/trace.out
Binary file not shown.
13 changes: 8 additions & 5 deletions internal/impl/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ func (d *Devbox) profilePath() (string, error) {
return absPath, errors.WithStack(os.MkdirAll(filepath.Dir(absPath), 0o755))
}

// syncPackagesToProfile ensures that all packages in devbox.json exist in the nix profile,
// and no more.
// syncPackagesToProfile can ensure that all packages in devbox.json exist in the nix profile,
// and no more. However, it may skip some steps depending on the `mode`.
func (d *Devbox) syncPackagesToProfile(ctx context.Context, mode installMode) error {
defer debug.FunctionTimer().End()
defer trace.StartRegion(ctx, "syncPackagesToProfile").End()
Expand Down Expand Up @@ -330,9 +330,12 @@ func (d *Devbox) syncPackagesToProfile(ctx context.Context, mode installMode) er
}

// Second, remove any packages from the nix-profile that are not in the config
itemsToKeep, err := d.removeExtraItemsFromProfile(ctx, profileDir, profileItems, packages)
if err != nil {
return err
itemsToKeep := profileItems
if mode != install {
itemsToKeep, err = d.removeExtraItemsFromProfile(ctx, profileDir, profileItems, packages)
if err != nil {
return err
}
}

// we are done if mode is uninstall
Expand Down
Binary file added trace.out
Binary file not shown.

0 comments on commit d2b5be5

Please sign in to comment.