You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
committed
perf(rm): replace per-iteration sort in distributedAlloc with a min-heap
Follow-up to the tie-break fix in PR #1788.
The previous implementation sorted the full candidate list inside the
allocation loop, paying O(n log n) per iteration for n iterations and
giving O(n² log n) overall. Since all annotated replicas from the same
underlying physical device share the same sort key, sorting at the
replica granularity is wasted work — only m (the number of distinct
physical devices contributing candidates) needs to be reordered.
Refactor to:
- Bucket candidates by their underlying physical device into a small
gpuAllocState per device, holding `used`, `pickedFrom`, and the
remaining annotated-ID candidates from that device.
- Initialize a min-heap of these states ordered primarily by `used`
(so devices with the fewest already-allocated replicas come first)
and tie-broken by `pickedFrom` (so devices we have not touched in
the current allocation are preferred when used counts match).
- On each iteration pop the best device, take one of its remaining
replicas, increment its counters, and push it back if more remain.
Total cost drops to O(n log m). The tie-break semantics from PR #1788
are preserved unchanged; existing tests still pass without modification.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: runatom-ai <258621014+runatom-ai@users.noreply.github.com>
Signed-off-by: Jonathan Meiri <33288957+Meiri28@users.noreply.github.com>
0 commit comments