Commit bf3760d
authored
refactor(flowcontrol): single-ended SafeQueue backed by container/heap (#1690)
* refactor: single-ended queue backed by heap
The dispatch SafeQueue was double-ended, but nothing consumed PeekTail
other than the flowQueueAccessor passthrough itself: dispatch needs only
the head, and eviction uses an independent ordering. With PeekTail gone
the queue is single-ended, so the bespoke max-min heap that gave O(1)
access to both ends is no longer justified.
- Remove the unused PeekTail from the SafeQueue contract and all
implementers, mocks, and tests; rename PeekHead -> Peek now that there
is a single end.
- Replace the hand-rolled max-min heap (maxminheap.go) with a standard
library container/heap priority queue (priorityqueue.go), eliminating
the custom bubble-up/down logic and the latent bug class it carried.
- Drop the side handle map: membership is validated by index identity
(a *heapItem lives in exactly one queue), preserving the contract's
Remove error semantics with less state. O(log n) targeted removal is
retained via per-item index tracking.
- Rename the registered queue MaxMinHeap -> PriorityQueue.
Signed-off-by: Luke Van Drie <lukevandrie@google.com>
* refactor(flowcontrol): apply review feedback on the priority queue
Addresses review comments from @shmuelk on #1690:
- Correct the new-file license headers to "2026 The llm-d Authors".
- Clarify the PriorityQueue doc: ordering is maintained by an internal
container/heap (the queue does not itself implement heap.Interface).
- Narrow the Add and Remove critical sections to the shared heap
mutation. Precondition checks (nil, type assertion) and the atomic
byteSize update move outside the lock; the isInvalidated and index
reads stay inside it, since those fields are written under the lock by
Remove/Cleanup/Drain and reading them lock-free would race.
- Compact Cleanup survivors in place instead of allocating a second
slice, clearing the vacated tail so removed items are not retained.
Signed-off-by: Luke Van Drie <lukevandrie@google.com>
---------
Signed-off-by: Luke Van Drie <lukevandrie@google.com>1 parent 546ea56 commit bf3760d
22 files changed
Lines changed: 405 additions & 737 deletions
File tree
- pkg/epp
- flowcontrol
- contracts/mocks
- controller/internal
- framework/plugins/queue
- registry
- framework
- interface/flowcontrol
- mocks
- plugins/flowcontrol/fairness
- globalstrict
- program-aware
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
167 | | - | |
| 166 | + | |
168 | 167 | | |
169 | 168 | | |
170 | 169 | | |
| |||
176 | 175 | | |
177 | 176 | | |
178 | 177 | | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
| 178 | + | |
| 179 | + | |
185 | 180 | | |
186 | 181 | | |
187 | 182 | | |
| |||
366 | 361 | | |
367 | 362 | | |
368 | 363 | | |
369 | | - | |
370 | | - | |
| 364 | + | |
| 365 | + | |
371 | 366 | | |
372 | 367 | | |
373 | 368 | | |
| |||
376 | 371 | | |
377 | 372 | | |
378 | 373 | | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
416 | | - | |
| 416 | + | |
417 | 417 | | |
418 | 418 | | |
419 | 419 | | |
| |||
Lines changed: 7 additions & 36 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | 49 | | |
54 | 50 | | |
55 | 51 | | |
| |||
79 | 75 | | |
80 | 76 | | |
81 | 77 | | |
82 | | - | |
| 78 | + | |
83 | 79 | | |
84 | 80 | | |
85 | | - | |
| 81 | + | |
86 | 82 | | |
87 | 83 | | |
88 | 84 | | |
| |||
91 | 87 | | |
92 | 88 | | |
93 | 89 | | |
94 | | - | |
| 90 | + | |
95 | 91 | | |
96 | 92 | | |
97 | 93 | | |
98 | | - | |
| 94 | + | |
99 | 95 | | |
100 | 96 | | |
101 | 97 | | |
| |||
121 | 117 | | |
122 | 118 | | |
123 | 119 | | |
124 | | - | |
| 120 | + | |
125 | 121 | | |
126 | | - | |
| 122 | + | |
127 | 123 | | |
128 | 124 | | |
129 | 125 | | |
| |||
132 | 128 | | |
133 | 129 | | |
134 | 130 | | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | 131 | | |
161 | 132 | | |
162 | 133 | | |
| |||
190 | 161 | | |
191 | 162 | | |
192 | 163 | | |
193 | | - | |
| 164 | + | |
194 | 165 | | |
195 | 166 | | |
196 | 167 | | |
| |||
Lines changed: 15 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
79 | 77 | | |
80 | 78 | | |
81 | 79 | | |
| |||
112 | 110 | | |
113 | 111 | | |
114 | 112 | | |
115 | | - | |
116 | | - | |
117 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
118 | 116 | | |
119 | | - | |
| 117 | + | |
120 | 118 | | |
121 | 119 | | |
122 | 120 | | |
123 | 121 | | |
124 | 122 | | |
125 | | - | |
| 123 | + | |
126 | 124 | | |
127 | 125 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
| 126 | + | |
137 | 127 | | |
138 | 128 | | |
139 | 129 | | |
| |||
156 | 146 | | |
157 | 147 | | |
158 | 148 | | |
159 | | - | |
160 | | - | |
| 149 | + | |
| 150 | + | |
161 | 151 | | |
162 | 152 | | |
163 | 153 | | |
| |||
404 | 394 | | |
405 | 395 | | |
406 | 396 | | |
407 | | - | |
| 397 | + | |
408 | 398 | | |
409 | 399 | | |
410 | 400 | | |
| |||
517 | 507 | | |
518 | 508 | | |
519 | 509 | | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
| 510 | + | |
525 | 511 | | |
526 | | - | |
| 512 | + | |
527 | 513 | | |
528 | 514 | | |
529 | 515 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
205 | | - | |
206 | | - | |
| 205 | + | |
| 206 | + | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
0 commit comments