Skip to content

Commit 7101168

Browse files
committed
[Feature] Accelerate the comparison for batched
1 parent bdee7bc commit 7101168

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

src/executorlib/standalone/batched.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
from concurrent.futures import Future
22

33

4-
def batched_futures(lst: list[Future], skip_lst: list[list], n: int) -> list[list]:
4+
def batched_futures(lst: list[Future], skip_set: set, n: int) -> list[list]:
55
"""
66
Batch n completed future objects. If the number of completed futures is smaller than n and the end of the batch is
7-
not reached yet, then an empty list is returned. If n future objects are done, which are not included in the skip_lst
7+
not reached yet, then an empty list is returned. If n future objects are done, which are not included in the skip_set
88
then they are returned as batch.
99
1010
Args:
1111
lst (list): list of all future objects
12-
skip_lst (list): list of previous batches of future objects
12+
skip_set (set): flat set of individual results already assigned to previous batches
1313
n (int): batch size
1414
1515
Returns:
1616
list: results of the batched futures
1717
"""
18-
skipped_elements_lst = [item for items in skip_lst for item in items]
19-
2018
done_lst = []
21-
n_expected = min(n, len(lst) - len(skipped_elements_lst))
19+
n_expected = min(n, len(lst) - len(skip_set))
2220
for v in lst:
23-
if v.done() and v.result() not in skipped_elements_lst:
21+
if v.done() and v.result() not in skip_set:
2422
done_lst.append(v.result())
2523
if len(done_lst) == n_expected:
2624
return done_lst

src/executorlib/task_scheduler/interactive/dependency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def _update_waiting_task(
346346
done_lst = batched_futures(
347347
lst=task_wait_dict["kwargs"]["lst"],
348348
n=task_wait_dict["kwargs"]["n"],
349-
skip_lst=[f.result() for f in task_wait_dict["kwargs"]["skip_lst"]],
349+
skip_set={item for f in task_wait_dict["kwargs"]["skip_lst"] for item in f.result()},
350350
)
351351
if len(done_lst) == 0:
352352
wait_tmp_lst.append(task_wait_dict)

0 commit comments

Comments
 (0)