-
Notifications
You must be signed in to change notification settings - Fork 50
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
Handling "tuple/any/all comprehensions" in the compiler. #545
Comments
Is this done now, with the pep-709 implementation as it landed? |
No, PEP 709 only handles list/set/dict comprehensions, not generator expressions. |
Unless we can implement |
The main difference is likely to be the number of resizes building the list. |
|
With a growth factor of We can look to change the growth factor for lists in another issue. |
Consider the following function containing a "tuple comprehension":
Which produces the following code:
What we would like is:
For list comprehensions, we can use escape analysis and inlining to remove the overhead.
@carljm is working on doing just that.
However, the above "tuple comprehension" is resistant to escape analysis as
tuple
could hypothetically be anything.We could use something like the approach described in @vstinner's FAT Python and convert:
into:
where
LIST_TO_TUPLE
is a VM instruction, not a call.With escape analysis and inlining, we should get the ideal code, with the small prefix:
We would expect the tier 2 optimizer to eliminate the prefix.
The above optimization also applies to
any
andall
as well astuple
.The potential for performance improvements is even greater in those cases as they tend to not exhaust the generator.
The text was updated successfully, but these errors were encountered: