settings.Load() copies the whole Settings (clone + deepCopy of every map and slice) for each caller. 133 places read one field of it and threw the rest away: the proxy for every outgoing request (netproxy), the GitHub token, the China mirror switch, a model's output cap, wire or price on a gateway request. With a real account in the tray, Load's clone was 26.6 MB of the 318 MB the process allocated in its first seven minutes, most of it through netproxy.For on each request. Each of them now reads settings.Shared(), the read-only settings every caller is given for the same settings.json. Only reads were changed: a scalar field (string, bool, int, float) or a map field's index read. A caller that keeps a whole map or slice, or calls a method on the settings, still takes Load's copy.
20 lines
772 B
Go
20 lines
772 B
Go
package update
|
|
|
|
import "github.com/yetone/magpie/internal/settings"
|
|
|
|
// Source is Settings' update source, "" when it is automatic: the
|
|
// usemagpie.ai feed, then GitHub when the feed can't be reached
|
|
// (fallback.go). settings.UpdateSourceSite never goes to GitHub, and
|
|
// settings.UpdateSourceGitHub never to usemagpie.ai (RootSir and Sakugar_
|
|
// on X: the site's download is slow). Whichever it is, the release goes
|
|
// through Release.verify: the same ed25519 signature over SHA256SUMS, the
|
|
// version inside it and every file's hash from it. MAGPIE_UPDATE_FEED, a
|
|
// test's feed, is never overridden by it.
|
|
func Source() string {
|
|
switch s := settings.Shared().UpdateSource; s {
|
|
case settings.UpdateSourceSite, settings.UpdateSourceGitHub:
|
|
return s
|
|
}
|
|
return ""
|
|
}
|