Skip to content

Commit ec0a703

Browse files
authored
[perf] Skip cache check if store path exists locally (#2042)
## Summary If store path exists locally, we know we can use that store path in `fetchClosure`. This helps speed up almost any operation where state is not up to date and we need to check if some store path is in cache. ## How was it tested? * added print statement `devbox run echo 5`
1 parent c237f94 commit ec0a703

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/devpkg/narinfo_cache.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import (
55
"fmt"
66
"io"
77
"net/http"
8+
"os"
89
"sync"
910
"time"
1011

1112
"github.com/pkg/errors"
1213
"go.jetpack.io/devbox/internal/boxcli/featureflag"
14+
"go.jetpack.io/devbox/internal/debug"
1315
"go.jetpack.io/devbox/internal/lock"
1416
"go.jetpack.io/devbox/internal/nix"
1517
"golang.org/x/sync/errgroup"
@@ -51,6 +53,7 @@ func (p *Package) IsInBinaryCache() (bool, error) {
5153
// package in the list, and caches the result.
5254
// Callers of IsInBinaryCache may call this function first as a perf-optimization.
5355
func FillNarInfoCache(ctx context.Context, packages ...*Package) error {
56+
defer debug.FunctionTimer().End()
5457
if !featureflag.RemoveNixpkgs.Enabled() {
5558
return nil
5659
}
@@ -145,6 +148,11 @@ func (p *Package) fetchNarInfoStatus(outputName string) (bool, error) {
145148

146149
outputInCache := map[string]bool{} // key = output name, value = in cache
147150
for _, output := range outputs {
151+
// if store path exists locally, then it is equivalent to being in the cache.
152+
if _, err := os.Stat(output.Path); err == nil {
153+
outputInCache[output.Name] = true
154+
continue
155+
}
148156
pathParts := nix.NewStorePathParts(output.Path)
149157
reqURL := BinaryCache + "/" + pathParts.Hash + ".narinfo"
150158
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)

0 commit comments

Comments
 (0)