Skip to content

Commit

Permalink
task_pool: avoid listing tasks where not necessary
Browse files Browse the repository at this point in the history
* Re-use the cached task list where appropriate.
* Switch to using the task dictionary for "in" comparisons
  for faster performance.
  • Loading branch information
oliver-sanders committed Mar 29, 2023
1 parent 65683fa commit caa9045
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cylc/flow/task_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(
self.task_name_list = self.config.get_task_name_list()
self.task_queue_mgr = IndepQueueManager(
self.config.cfg['scheduling']['queues'],
self.config.get_task_name_list(),
self.task_name_list,
self.config.runtime['descendants']
)
self.tasks_to_hold: Set[Tuple[str, 'PointBase']] = set()
Expand All @@ -137,7 +137,7 @@ def set_stop_task(self, task_id):
"""Set stop after a task."""
tokens = Tokens(task_id, relative=True)
name = tokens['task']
if name in self.config.get_task_name_list():
if name in self.config.taskdefs:
task_id = TaskID.get_standardised_taskid(task_id)
LOG.info("Setting stop task: " + task_id)
self.stop_task_id = task_id
Expand Down Expand Up @@ -174,7 +174,7 @@ def load_from_point(self):
flow_num = self.flow_mgr.get_new_flow(
f"original flow from {self.config.start_point}")
self.compute_runahead()
for name in self.config.get_task_name_list():
for name in self.task_name_list:
tdef = self.config.get_taskdef(name)
point = tdef.first_point(self.config.start_point)
self.spawn_to_rh_limit(tdef, point, {flow_num})
Expand Down Expand Up @@ -925,7 +925,7 @@ def reload_taskdefs(self) -> None:
del self.task_queue_mgr
self.task_queue_mgr = IndepQueueManager(
self.config.cfg['scheduling']['queues'],
self.config.get_task_name_list(),
self.task_name_list,
self.config.runtime['descendants']
)

Expand Down Expand Up @@ -1385,7 +1385,7 @@ def spawn_on_all_outputs(
def can_spawn(self, name: str, point: 'PointBase') -> bool:
"""Return True if the task with the given name & point is within
various workflow limits."""
if name not in self.config.get_task_name_list():
if name not in self.config.taskdefs:
LOG.debug('No task definition %s', name)
return False
# Don't spawn outside of graph limits.
Expand Down

0 comments on commit caa9045

Please sign in to comment.