Files
magpie/internal
yetone 57855191f0 provider: a price looks its provider up without copying them all (#2278)
byIDOrWas, which every model's price (BasePriceIn, UserBasePriceIn)
and a few model preferences go through, read All(): a copy of every
provider, its keys, headers, models and account maps, to find one. A
Sessions poll prices every model of every call, so that was the next
largest allocator of a poll. It now looks among the shared providers
(sharedAll, as Find does) and clones only the one it found, which stays
the caller's to change.

Measured on mote with the owner's real account, 40 /api/sessions
polls, `magpie heap` alloc_space diff:
  before (w7): byIDOrWas 9.74 MB (All 9.74: its copies 5.7, sharedAll
  4.0)
  after  (w8): byIDOrWas 3.52 MB, all of it sharedAll's rebuild when
  the hold expires; All gone from the poll
CPU over 30 s of polling: 1.37 s (w7) -> 1.29 s.

Test: TestByIDOrWasCopiesOnlyItsOwn (new), 40 providers of 5 keys each
under Hold: a change to the returned provider doesn't reach the shared
ones, and the lookup allocates under a tenth of All. With the old
models.go it fails (1560 allocations, against 1560 for All).
Run on mica at 10c331531 plus this change: go vet ./internal/provider
for darwin, linux and windows clean; go test ./internal/provider ok
(130 s).
Not tried: Windows or Linux runs; the change is which list is read.
2026-11-12 05:30:42 +08:00
..
…
…
…
…
…
…
…
…
…
…
…
…