Skip to content

Commit d2b5be5

Browse files
authored
[perf] in syncPackagesToProfile, only removeExtraItemsFromProfile is mode is not install (#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
1 parent b6d0b20 commit d2b5be5

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed
45.1 KB
Binary file not shown.

internal/impl/packages.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ func (d *Devbox) profilePath() (string, error) {
301301
return absPath, errors.WithStack(os.MkdirAll(filepath.Dir(absPath), 0o755))
302302
}
303303

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

332332
// Second, remove any packages from the nix-profile that are not in the config
333-
itemsToKeep, err := d.removeExtraItemsFromProfile(ctx, profileDir, profileItems, packages)
334-
if err != nil {
335-
return err
333+
itemsToKeep := profileItems
334+
if mode != install {
335+
itemsToKeep, err = d.removeExtraItemsFromProfile(ctx, profileDir, profileItems, packages)
336+
if err != nil {
337+
return err
338+
}
336339
}
337340

338341
// we are done if mode is uninstall

trace.out

49.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)