python / cpython

The Python programming language
https://www.python.org/
Other
61.09k stars 29.49k forks source link

Tier 2 optimizer: constant propagate through attribute loads #120323

Open Fidget-Spinner opened 1 month ago

Fidget-Spinner commented 1 month ago

Feature or enhancement

Proposal:

Now that we have type versions installed in https://github.com/python/cpython/issues/119258 . We can use the information to constant propagate through attribute loads.

This means something like

dict.fromkeys()

becomes the same as

dict_fromkeys()

Note: this is just a constant load, not an attribute lookup!

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Fidget-Spinner commented 1 month ago

CC @saulshanabrook this is building off your work!

Fidget-Spinner commented 1 month ago

Nevermind, I forgot we yet to have a specialization for builtin class loads, so we can't do this until we add the tier 1 specialization.

For now, I can add this for tier 2 just for Python classes.