/api/providers took ~25ms of CPU a call with the owner's real config (25
providers, plugins signed in), polled by every open window. Its profile
had file system calls at about half, each repeated for every provider
the list shows:
- StampNow stat'ed providers.json, settings.json and the catalog for every
provider (KeptListing); under a request's Hold it is looked at once.
- plugin.ListedAt was asked for every plugin provider's Listed(); once a
request (heldOf "plugin-listed").
- pluginLogins took logins.json's lock, a file opened across magpies,
for every plugin even with nothing to change. It now settles the list
as read first, and takes the lock and settles again from a fresh read
only when something changes.
- clientShape read and parsed client-shapes.json for every relay a list
shows (TestsAs); parsed once until the file changes (filememo), a copy
given out.
- Logins(agent) took the same lock for every provider, twice with its
account models; listed once an agent a request, a copy each, listed
anew after a write (writePrivate's filememo.Forget).
Run (on mote unless named):
- go test ./internal/provider ./internal/gui -timeout 45m: provider ok
(102s) with the new tests; gui red on TestMainWindowCorners (macOS 27,
#3949) and on TestSettingsSaveKeepsWhatItDoesNotSend, red on main since
b09349d17, fixed by #4514's commit before this one.
- At the pushed head (rebased on e84870f17): go test ./internal/provider
ok (100.7s), ./internal/plugin ok (102.7s), TestLoginsListedOnceARequest
-count=5 ok (it now clears the 30s look another test left), gui
TestSettingsSaveKeepsWhatItDoesNotSend and TestCoreScriptBudget ok;
GOOS=linux and windows go vet ./internal/provider ok.
Then rebased onto 3defaf662 (internal/agent dsh.go only); not rerun.
- New tests: TestStampLooksOnceARequest, TestClientShapeParsedOnceUntilWritten,
TestLoginsListedOnceARequest, and TestAccountListsCopyNoLoginsUnchanged
now counts the lock. Broken by hand, each goes red: "51 stamps in one
request looked 51 times, want 1", "30 asks parsed the file 30 times",
"20 plugin lists with nothing to change took the lock 20 times",
"20 lists in one request listed 20 times".
- GOOS=linux and windows go vet ./internal/provider: ok. gofmt clean.
- Real config, on this Mac: a copy of the owner's ~/.config/magpie in an
offline sandbox HOME (proxy :9), 200 GET /api/providers each:
v0.1.2541 5.04s CPU (25.2ms a call, median 22.5ms wall), this change
4.55s (22.8ms, median 20.3ms). The profile's stats under StampNow fell
from 2.17s to 0.34s.
Not run: the full ./... suite; GUI (browser) tests, as nothing the page
gets changed. What is left in the profile: StepFun's sign-in file,
sync.json, plugin icons and agent detection, each read once a request.
SawClient keeps the headers a client last came with, and writes
client-shapes.json (read, unmarshal, marshal, synced temp, rename) when
they differ from what it last wrote. Each Codex window sends its own
X-Codex-Window-Id, which was taken as part of Codex's shape, so with two
or more Codex sessions on a keyed provider nearly every request rewrote
and fsynced the file. The window id and a retry's count
(X-Stainless-Retry-Count) are now left out, like the session and turn
ids already were.
Run (sandbox HOME, real deepseek account, three real `codex exec`
0.162.1 sessions through a -tags nogui build on :3482, 60s each,
counting the file's mtime/inode changes every 50ms):
origin/main 20d63621d: 85 rewrites over 91 requests
this change: 2 rewrites over 97 requests (the first strips
the window id kept before), keeping Originator,
User-Agent and X-Codex-Beta-Features
In the base run's 120s CPU profile (253 requests) SawClient's reads and
writes were ~0.22s of 7.5s.
TestClientShapeWrittenOnceForTwoWindows: ok; with test_as.go at HEAD it
FAILs ("client-shapes.json was written again for another window's
request"). go test -run 'TestAs|Shape|ClientHeader|CodexHeaders|
ClaudeCodeHeaders|AskedAs' ./internal/provider ./internal/gateway
./internal/cli ok. gofmt clean; go vet -tags nogui GOOS=linux and
windows ./internal/provider ok. Not run: the whole ./... suite.