Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize valid_workers #4329

Merged
merged 6 commits into from
Dec 9, 2020
Merged

Optimize valid_workers #4329

merged 6 commits into from
Dec 9, 2020

Conversation

jakirkham
Copy link
Member

Annotates valid_workers for Cython optimization. In particular ensure it always returns a set or None (in case all workers are viable instead of True as before). Also use unique variables when they have already been assigned or if new results may have different types than before. This makes it easier to annotate these variables and for Cython to then optimize usage thereof.


if not valid_workers and not ts._loose_restrictions and self.workers:
if valid_workers == set() and not ts._loose_restrictions and self.workers:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised that it makes sense to create an empty set each time.

Copy link
Member Author

@jakirkham jakirkham Dec 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think you are right; we can do better. Will push a fix.

In [4]: %timeit s == set()
91.3 ns ± 0.747 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

In [5]: %timeit s is not None and not s
37.3 ns ± 0.373 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

(tested with s = set())

@mrocklin
Copy link
Member

mrocklin commented Dec 8, 2020

+1

@mrocklin
Copy link
Member

mrocklin commented Dec 8, 2020

+1

@jakirkham
Copy link
Member Author

Thanks Matt! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants