Heap profile diff of the live magpie (v0.1.2906, /v1/magpie/heap, two idle minutes with the window open: 269 MB allocated): - ownCodex found the codex provider through provider.All, a copy of every provider, on each look (~9 MB). Its picks are now kept per stamp (codexPicks, stampedLists), read only. - Codex's model and effort fields copied magpie's whole model list on each Options call, every poll of the effort field (~11 MB). They read sharedModels, the list kept, which they only read. - visibleQuotas built every provider's offered models to narrow Gemini's and Antigravity's quotas (~20 MB). exposedIDs builds the providers asked only. Run (mote, at this tree): - gofmt -l internal, go vet ./..., GOOS=windows and GOOS=linux go vet ./internal/agent/ ./internal/provider/: clean - go test -count=1 -timeout 45m ./... (all three commits' tree): 85 packages ok, internal/gateway 748s, internal/provider 193s. Two red: internal/gui's TestMainWindowCorners/macOS_26_SDK, mote's macOS 27 (#3949, filed before, untouched here), and internal/agent's TestCodexEffortOptionsReadTheKeptList, whose bar counted the environment's copy (see the effort test's comment), fixed in its test. - then go test -count=1 -timeout 45m ./internal/agent/ with that fix: ok (200.1s) Broken by hand: - codexPicks through provider.Find again: 285 allocations, red (TestCodexOwnModelsFollowPicks, bar 20). - the effort field on magpieModels again: 199896 bytes a look past its StampNow's 1712, red (TestCodexEffortOptionsReadTheKeptList, bar 20000). The test takes the look's StampNow off: os.Environ copies the environment, and each t.Setenv before it in the package made that longer (an Unsetenv leaves its slot), ~56 KB a look in the whole package; run alone it is 1.7 KB. - exposedIDs without the ids check: "other" built, red (TestExposedIDsBuildsOnlyTheProvidersAsked). Not tried: the numbers on the live app after this build; that profile is taken once it is released.
42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
package agent
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// Codex's effort field reads the models magpie keeps for it, not a copy
|
|
// of the whole list on each look: the window asks it on every poll.
|
|
func TestCodexEffortOptionsReadTheKeptList(t *testing.T) {
|
|
home, _ := codexHome(t, `{"OPENAI_API_KEY":"sk-x"}`, "model = \"fake/m1\"\nmodel_provider = \"magpie\"\n")
|
|
var ids []string
|
|
for i := range 400 {
|
|
ids = append(ids, fmt.Sprintf("m%d", i))
|
|
}
|
|
if err := provider.Save(provider.Provider{ID: "fake", Name: "Fake", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: ids}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var effort *Field
|
|
cx := codex(home)
|
|
for i := range cx.Fields {
|
|
if cx.Fields[i].Key == "effort" {
|
|
effort = &cx.Fields[i]
|
|
}
|
|
}
|
|
if effort == nil {
|
|
t.Fatal("no effort field")
|
|
}
|
|
cur := map[string]string{"model": "fake/m1"}
|
|
effort.Options(cur)
|
|
// a copy of 400 models is one allocation, but of ~100 KB: count bytes
|
|
// less the look's StampNow, whose os.Environ copies the environment:
|
|
// every t.Setenv of the package before this one made it longer (an
|
|
// Unsetenv leaves its slot), ~56 KB a look by the time this runs
|
|
per, stamp := leastBytes(50, func() { effort.Options(cur) }), leastBytes(50, func() { provider.StampNow() })
|
|
if per > stamp && per-stamp > 20_000 {
|
|
t.Fatalf("a look at Codex's efforts allocated %d bytes past its stamp's %d, want at most 20000", per-stamp, stamp)
|
|
}
|
|
}
|