appdir.Config and Cache, catalog.CachePath and LivePath, settings.Path, provider.Path and the logins path each ran filepath.Join on every call, and they are called on every read of a cached file, many times a request. Those joins were 70 MB of the 1.4 GB twenty window polls allocated. appdir.Join and JoinFile keep each (dir, name, ext) they joined, up to 4096 of them, so a path named again is the same string. A changed HOME or folder is a different key, so a test's sandbox still gets its own path. TestFoldersJoinedOnce and TestLivePathNamedOnce: 0 allocations a call. Broken by hand on mote (the files before this change) they are red at 1 allocation a call, and 3 for LivePath. Run on mote at this tree (ond714c4216): gofmt clean; vet ok on darwin, windows and linux (appdir, catalog, settings, provider); go build ok; appdir, catalog, settings (49s), provider (187s), agent (324s) and gateway (1244s) ok. At the pushed head (on019bfc951, which adds provider.Held): vet of appdir, catalog, settings, provider and gui ok, go build ok, appdir, catalog and gui's TestAccountLabelsBuildTheAgentsOnce ok.
18 lines
543 B
Go
18 lines
543 B
Go
package catalog
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// A provider's list file is named once, not on each read of the list: a
|
|
// look at the providers reads it for every model.
|
|
func TestLivePathNamedOnce(t *testing.T) {
|
|
if got, want := LivePath("openai"), filepath.Join(filepath.Dir(CachePath()), "models", "openai.json"); got != want {
|
|
t.Fatalf("LivePath = %q, want %q", got, want)
|
|
}
|
|
if n := testing.AllocsPerRun(20, func() { LivePath("openai") }); n > 0 {
|
|
t.Errorf("LivePath with the folders unchanged: %.0f allocations", n)
|
|
}
|
|
}
|