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.
26 lines
832 B
Go
26 lines
832 B
Go
package provider
|
|
|
|
import "testing"
|
|
|
|
// The quotas narrowed by the models offered build the lists of their own
|
|
// providers only: every other provider's, each account's and plugin's,
|
|
// was built on each usage read for nothing.
|
|
func TestExposedIDsBuildsOnlyTheProvidersAsked(t *testing.T) {
|
|
isolate(t)
|
|
for _, p := range []Provider{
|
|
{ID: "asked", Name: "Asked", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"gemini-a"}},
|
|
{ID: "other", Name: "Other", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1"}},
|
|
} {
|
|
if err := Save(p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
got := exposedIDs("asked", "antigravity")
|
|
if _, ok := got["other"]; ok || len(got) != 1 {
|
|
t.Fatalf("built %v, want the one asked alone", got)
|
|
}
|
|
if !got["asked"]["gemini-a"] {
|
|
t.Fatalf("its offered models: %v", got["asked"])
|
|
}
|
|
}
|