Skip to content

Conversation

@BobTheBuidler
Copy link
Contributor

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

BobTheBuidler and others added 4 commits October 24, 2025 16:26
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
# 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):
Copy link
Contributor Author

@BobTheBuidler BobTheBuidler Oct 24, 2025

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:?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or a native generator*?

Copy link
Contributor Author

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.

@BobTheBuidler BobTheBuidler changed the title [mypyc] feat: reorder gens for speed in ForZip [mypyc] feat: reorder gens for speed in ForZip.gen_condition Oct 24, 2025
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.

1 participant