[Python-Dev] Re: Why doesn't peephole optimise away operations with fast locals?

2021年10月10日 21:37:22 -0700

Sorry for the brainfart earlier. We've got a discussion in our "ideas"
database already about this, start reading here:
https://github.com/faster-cpython/ideas/issues/16#issuecomment-881439738 
On Sun, Oct 10, 2021 at 2:55 PM Dennis Sweeney <[email protected]>
wrote:
> STORE_FAST can also be caused by the assignment to a loop variable, so
> STORE/LOAD pairs can come about with things like this:
>
> >>> def f():
> ... for x in stuff:
> ... x.work()
> ...
> ...
> >>> from dis import dis
> >>> dis(f)
> 2 0 LOAD_GLOBAL 0 (stuff)
> 2 GET_ITER
> >> 4 FOR_ITER 6 (to 18)
> 6 STORE_FAST 0 (x)
>
> 3 8 LOAD_FAST 0 (x)
> 10 LOAD_METHOD 1 (work)
> 12 CALL_METHOD 0
> 14 POP_TOP
> 16 JUMP_ABSOLUTE 2 (to 4)
>
> 2 >> 18 LOAD_CONST 0 (None)
> 20 RETURN_VALUE
>
> I'd guess that they'd be somewhat common in comprehensions too:
>
> >>> dis(x**2 for x in range(1000))
> 0 GEN_START 0
>
> 1 2 LOAD_FAST 0 (.0)
> >> 4 FOR_ITER 7 (to 20)
> 6 STORE_FAST 1 (x)
> 8 LOAD_FAST 1 (x)
> 10 LOAD_CONST 0 (2)
> 12 BINARY_POWER
> 14 YIELD_VALUE
> 16 POP_TOP
> 18 JUMP_ABSOLUTE 2 (to 4)
> >> 20 LOAD_CONST 1 (None)
> 22 RETURN_VALUE
>
>
> In fact, there's already a bpo issue from 2019:
> https://bugs.python.org/issue38381
> _______________________________________________
> Python-Dev mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/73BMYW3TY7PJB7KRQ3Q3OROGU5UJVJAW/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/BPDXGJYAMI7UCIDECB5XXQ6VQ4LGH7OG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to