-
-
Notifications
You must be signed in to change notification settings - Fork 718
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 decide_worker
#4332
Optimize decide_worker
#4332
Conversation
Helps Cython verify that this matches the expected `return` type before `return`ing.
This winds up being a bit faster than calling `first`. ```python In [1]: from tlz import first In [2]: s = {"a"} In [3]: %timeit first(s) 76 ns ± 0.17 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each) In [4]: %%timeit ...: for e in s: ...: break ...: 42.4 ns ± 0.429 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each) ```
As the case where there are idle workers and when there are not are largely the same (except with collection of workers they draw from), choose between the two collections at the beginning. Then spend the remainder of the code on the selection logic.
Since we use this in a couple of cases, go ahead and assign it to a variable initially and reuse that variable afterwards.
As this variable refers to a `WorkerState` instance, rename it to follow the convention we have with `WorkerState` variable names.
f771e9e
to
f8b8c14
Compare
Makes it easier for Cython to identify that this has the expected return type when checking the value returned.
f8b8c14
to
b94310f
Compare
|
||
return worker | ||
return ws |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for standardizing pronouns along the way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's certainly made it a lot easier to understand where things can be annotated 🙂
It looks like we're going the route of doing easy optimizations before splitting things out to a cythonized class and a non-cythonized class. Is this correct? |
Yes and no. I started a refactoring branch as well. Though I think the particular transition these changes are associated with, |
Annotate variables in
decide_worker
(both method and function). Deduplicate some code within thedecide_worker
method. Also tune thedecide_worker
function fast path.