Skip to content

Commit

Permalink
Get len(candidates) and branch based on that
Browse files Browse the repository at this point in the history
Cython will turn this into a very efficient `switch...case` statement.
So this cuts down on the overhead of comparisons and checks (paying them
once when computing the length). Then focuses on just checking this C
typed integral value for which `case` to run.
  • Loading branch information
jakirkham committed Feb 10, 2021
1 parent 7386974 commit eb3e6c3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions distributed/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6892,9 +6892,10 @@ def decide_worker(
else:
return None

if not candidates:
ncandidates: Py_ssize_t = len(candidates)
if ncandidates == 0:
ws = None
elif len(candidates) == 1:
elif ncandidates == 1:
for ws in candidates:
break
else:
Expand Down

0 comments on commit eb3e6c3

Please sign in to comment.