Skip to content

Commit 893e550

Browse files
authored
[perf] Fix regression (#2079)
## Summary This is mostly a revert of a few changes made in 3246587 that introduced a perf regression. ## How was it tested? * builds * ran `devbox install` on a project that had 2 packages cached in nix cache and 1 package cached in jetify cache
1 parent ca5b5e0 commit 893e550

File tree

4 files changed

+26
-19
lines changed

4 files changed

+26
-19
lines changed

internal/devpkg/narinfo_cache.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ func FillNarInfoCache(ctx context.Context, packages ...*Package) error {
8686
group, _ := errgroup.WithContext(ctx)
8787
for _, p := range eligiblePackages {
8888
pkg := p // copy the loop variable since its used in a closure below
89-
outputs, err := pkg.GetOutputs()
89+
outputNames, err := pkg.GetOutputNames()
9090
if err != nil {
9191
return err
9292
}
9393

94-
for _, output := range outputs {
95-
name := output.Name
94+
for _, outputName := range outputNames {
95+
name := outputName
9696
group.Go(func() error {
9797
_, err := pkg.fetchNarInfoStatusOnce(name)
9898
return err

internal/devpkg/package.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,13 @@ func (p *Package) PatchGlibc() bool {
241241
// Installables for this package. Installables is a nix concept defined here:
242242
// https://nixos.org/manual/nix/stable/command-ref/new-cli/nix.html#installables
243243
func (p *Package) Installables() ([]string, error) {
244-
outputs, err := p.GetOutputs()
244+
outputNames, err := p.GetOutputNames()
245245
if err != nil {
246246
return nil, err
247247
}
248248
installables := []string{}
249-
for _, output := range outputs {
250-
i, err := p.InstallableForOutput(output.Name)
249+
for _, outputName := range outputNames {
250+
i, err := p.InstallableForOutput(outputName)
251251
if err != nil {
252252
return nil, err
253253
}
@@ -675,17 +675,24 @@ func (p *Package) DocsURL() string {
675675
return ""
676676
}
677677

678-
// GetOutputs returns the nix package outputs. Outputs can be
678+
// GetOutputNames returns the names of the nix package outputs. Outputs can be
679679
// specified in devbox.json package fields or as part of the flake reference.
680-
// If they exist in a cache, the cache URI is non-empty.
681-
func (p *Package) GetOutputs() ([]Output, error) {
682-
defer debug.FunctionTimer().End()
680+
func (p *Package) GetOutputNames() ([]string, error) {
683681
if p.IsRunX() {
684-
return nil, nil
682+
return []string{}, nil
685683
}
686684

687-
names, err := p.outputs.GetNames(p)
688-
if err != nil {
685+
return p.outputs.GetNames(p)
686+
}
687+
688+
// GetOutputsWithCache return outputs and their cache URIs if the package is in the binary cache.
689+
// n+1 WARNING: This will make an http request if FillNarInfoCache is not called before.
690+
// Grep note: this is used in flake template
691+
func (p *Package) GetOutputsWithCache() ([]Output, error) {
692+
defer debug.FunctionTimer().End()
693+
694+
names, err := p.GetOutputNames()
695+
if err != nil || len(names) == 0 {
689696
return nil, err
690697
}
691698

internal/shellgen/flake_input.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,19 @@ func (f *flakeInput) BuildInputsForSymlinkJoin() ([]*SymlinkJoin, error) {
8989
return nil, errors.New("patch_glibc is not yet supported for packages with non-default outputs")
9090
}
9191

92-
outputs, err := pkg.GetOutputs()
92+
outputNames, err := pkg.GetOutputNames()
9393
if err != nil {
9494
return nil, err
9595
}
9696

9797
joins = append(joins, &SymlinkJoin{
9898
Name: pkg.String() + "-combined",
99-
Paths: lo.Map(outputs, func(output devpkg.Output, _ int) string {
99+
Paths: lo.Map(outputNames, func(outputName string, _ int) string {
100100
if !f.IsNixpkgs() {
101-
return f.Name + "." + attributePath + "." + output.Name
101+
return f.Name + "." + attributePath + "." + outputName
102102
}
103103
parts := strings.Split(attributePath, ".")
104-
return f.PkgImportName() + "." + strings.Join(parts[2:], ".") + "." + output.Name
104+
return f.PkgImportName() + "." + strings.Join(parts[2:], ".") + "." + outputName
105105
}),
106106
})
107107
}
@@ -229,7 +229,7 @@ func (k *keyedSlice) getOrAppend(key string) *flakeInput {
229229
// Multiple outputs -> SymlinkJoin.
230230
// Single or no output -> directly use in buildInputs
231231
func needsSymlinkJoin(pkg *devpkg.Package) (bool, error) {
232-
outputNames, err := pkg.GetOutputs()
232+
outputNames, err := pkg.GetOutputNames()
233233
if err != nil {
234234
return false, err
235235
}

internal/shellgen/tmpl/flake_remove_nixpkgs.nix.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
devShells.{{ .System }}.default = pkgs.mkShell {
3939
buildInputs = [
4040
{{- range $_, $pkg := .Packages }}
41-
{{- range $_, $output := $pkg.GetOutputs }}
41+
{{- range $_, $output := $pkg.GetOutputsWithCache }}
4242
{{ if $output.CacheURI -}}
4343
(builtins.trace "downloading {{ $pkg.Versioned }}" (builtins.fetchClosure {
4444
{{/*

0 commit comments

Comments
 (0)