-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[mypyc] feat: reorder gens for speed in ForZip.gen_condition
#20116
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
base: master
Are you sure you want to change the base?
Conversation
Not all generators have an equally fast gen_condition, some are quite fast while others quite the opposite This PR orders them in what I see to be a reasonably fastest -> slowest order
for more information, see https://pre-commit.ci
mypyc/irbuild/for_helpers.py
Outdated
| # this is a failsafe for ForHelper classes which might have been added after this commit but not added to this function's code | ||
| leftovers = [g for g in gens if g not in ordered + for_iterable] | ||
|
|
||
| for i, gen in enumerate(ordered + leftovers + for_iterable): |
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.
hmmm does this break Python semantics in cases where the input is an Iterator with def __iter__(self) -> Self:?
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.
or a native generator*?
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.
I guess we could defer to the existing code in those cases. Which renders this PR a whole lot less useful, but it still leaves us with a tangible improvement in some cases.
ForZip.gen_condition
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Not all generators have an equally fast gen_condition, some are quite fast while others quite the opposite
This PR orders them in what I see to be a reasonably fastest -> slowest order