least_conn mirror selection stable-sorted the RR-rotated pool with a
comparator that called inflightCounter on every comparison. Each call did a
remoteName+"\x00"+url concat plus a sync.Map LoadOrStore with a speculative
new(atomic.Int64), so selection cost O(n log n) map lookups and allocations
per request on the cache-miss path.
Snapshot each mirror's in-flight count exactly once, then sort the snapshot by
plain int, making selection O(n) map loads with zero comparator allocations:
- Add read-only inflightCount(name, url) int64: plain sync.Map Load, returns 0
when the counter is absent (no LoadOrStore, no speculative allocation).
- least_conn branch builds a {url, count} snapshot via one inflightCount per
rotated URL, sort.SliceStable by count ascending, then extracts the URLs.
- beginAttempt/endAttempt keep the create-on-write inflightCounter path; they
legitimately need to create the gauge.
Behavior is unchanged: least-loaded first, RR rotation as the stable tie-break,
round_robin and single-URL paths untouched. Added a multi-mirror tie-break test
asserting all-equal load yields the RR rotation.