Skip to content

Commit

Permalink
Instantiate Job by id directly when iterating over ids.
Browse files Browse the repository at this point in the history
`open_job` is a user-facing function and performs error checking on the id. This check
involves a stat call to verify the job directory exists. When `Project` is looping over
ids from `_get_job_ids`, the directory is known to exist (subject to race conditions).
`stat` calls are expensive, especially on networked filesystems.

Instantiating `Job` directly bypasses this check in `open_job`.
  • Loading branch information
joaander committed Feb 7, 2024
1 parent e20194f commit 712ed09
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions signac/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ def get_job(cls, path=None):
project = cls.get_project(os.path.join(job_path, os.pardir))

# Return the matched job id from the found project
return project.open_job(id=job_id)
return Job(project=project, id_=job_id)

def __getstate__(self):
state = dict(self.__dict__)
Expand Down Expand Up @@ -1688,7 +1688,7 @@ def __init__(self, project, ids):
self._ids_iterator = iter(ids)

def __next__(self):
return self._project.open_job(id=next(self._ids_iterator))
return Job(project=self._project, id_=next(self._ids_iterator))

def __iter__(self):
return type(self)(self._project, self._ids)
Expand Down

0 comments on commit 712ed09

Please sign in to comment.