Skip to content

Commit

Permalink
Make _unknown_durations an ordinary dict
Browse files Browse the repository at this point in the history
As `defaultdict`s are difficult for Cython to optimize and usually a
`dict` will suffice, change `_unknown_duractions` to a `dict` to allow
Cython to use Python C API specific to `dict`s.
  • Loading branch information
jakirkham committed Feb 9, 2021
1 parent b2e7f77 commit bc3f76a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions distributed/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,7 @@ class SchedulerState:
_task_metadata: dict
_total_nthreads: Py_ssize_t
_total_occupancy: double
_unknown_durations: object
_unknown_durations: dict
_unrunnable: set
_validate: bint
_workers: object
Expand Down Expand Up @@ -1645,7 +1645,7 @@ def __init__(
self._task_metadata = dict()
self._total_nthreads = 0
self._total_occupancy = 0
self._unknown_durations = defaultdict(set)
self._unknown_durations = dict()
if unrunnable is not None:
self._unrunnable = unrunnable
else:
Expand Down Expand Up @@ -2645,8 +2645,11 @@ def get_task_duration(self, ts: TaskState, default: double = -1) -> double:
"""
duration: double = ts._prefix._duration_average
if duration < 0:
s: set = self._unknown_durations[ts._prefix._name]
s: set = self._unknown_durations.get(ts._prefix._name)
if s is None:
self._unknown_durations[ts._prefix._name] = s = set()
s.add(ts)

if default < 0:
duration = UNKNOWN_TASK_DURATION
else:
Expand Down

0 comments on commit bc3f76a

Please sign in to comment.