O(1) slot allocation in ReqToTokenPool.alloc() (#32208)
Co-authored-by: Zhiqiang Xie <xiezhq@stanford.edu>
This commit is contained in:
co-authored by
Zhiqiang Xie
parent
aadb9720fe
commit
c58953d90a
@@ -306,8 +306,14 @@ class ReqToTokenPool:
|
||||
need_size = len(reqs) - len(reusing)
|
||||
if need_size > len(self.free_slots):
|
||||
return None
|
||||
select_index = self.free_slots[:need_size]
|
||||
self.free_slots = self.free_slots[need_size:]
|
||||
if need_size > 0:
|
||||
# Pop from the tail: O(need_size), unlike a prefix pop which is
|
||||
# O(len(free_slots)).
|
||||
select_index = self.free_slots[-need_size:]
|
||||
del self.free_slots[-need_size:]
|
||||
else:
|
||||
# Handled separately: free_slots[-0:] is the entire list, not [].
|
||||
select_index = []
|
||||
offset = 0
|
||||
for r in reqs:
|
||||
if r.req_pool_idx is None:
|
||||
|
||||
Reference in New Issue
Block a user