From a72850ee75a5643e4b225f54700678d42005739a Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Wed, 3 Feb 2021 11:44:34 +0100 Subject: [PATCH] Don't check if item is in list Just do set intersection. This is surprisingly something that takes up a good amount of CPU time on job handlers if there are a lot of jobs. With cumulative line-based profiling this is one of the top lines in Galaxy code. --- lib/galaxy/jobs/handler.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/jobs/handler.py b/lib/galaxy/jobs/handler.py index 4cff86a0308..4de1b62e7f5 100644 --- a/lib/galaxy/jobs/handler.py +++ b/lib/galaxy/jobs/handler.py @@ -436,9 +436,8 @@ class JobHandlerQueue(Monitors): if not self.track_jobs_in_database: self.waiting_jobs = new_waiting_jobs # Remove cached wrappers for any jobs that are no longer being tracked - for id in list(self.job_wrappers.keys()): - if id not in new_waiting_jobs: - del self.job_wrappers[id] + for id in set(self.job_wrappers.keys()) - set(new_waiting_jobs): + del self.job_wrappers[id] # Flush, if we updated the state self.sa_session.flush() # Done with the session