[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Mark Shannon




On 28/11/2021 6:28 am, raymond.hettin...@gmail.com wrote:

For the benefit of the audience on python-dev, you should also mention that 
this proposal and associated PR has been twice discussed and rejected on the 
tracker:

https://bugs.python.org/issue45907
https://bugs.python.org/issue45843

The response just given by Skip pretty much matches the comments already given 
by Batuhan, Pablo, and Serhiy.  So far, no one who has looked at this thinks 
this should be done.


That is not entirely true: 
https://github.com/python/cpython/pull/29639#issuecomment-974146979
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/YDNHIZQOW2IWPGKLFQ6Y5LLXD42TBQMN/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Skip Montanaro
> That is not entirely true: 
> https://github.com/python/cpython/pull/29639#issuecomment-974146979

The only places I've seen "if 0:" or "if False:" in live code was for
debugging. Optimizing that hardly seems necessary. In any case, the
original comment was about comparisons of two constants. I suppose
sweeping up all of that into a constant expression folding/elimination
step performed on the AST and/or during peephole optimization would
cover both cases.

Skip
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/HW3WJUPENKNZ2NNJ52LRRM7HLFWB44XH/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Remove asyncore, asynchat and smtpd modules

2021-11-28 Thread Steve Holden
Speaking as the author of the doc pages, I think I can safely say that
anyone who was smart enough to use asyncore/asychat back in the day (I used
it in "Python Web Programming") is almost certainly smart enough to have
migrated away from them long ago. They were an interesting approach to
asynchronous networking, but I think it's safe to say that world has moved
on in 20 years.

Kind regards,
Steve


On Wed, Nov 17, 2021 at 6:13 AM Kyle Stanley  wrote:

> I think it would be fine to wait just one release, until 3.12. Makes no
> substantial maintenance difference and maybe easier for users with more
> advanced notice, especially for module removal.
>
> I also wonder if maybe we should scale delay between dep -> removal based
> on maintenance burden estimate, rather than 2 versions for all. Module
> removal certainly takes more effort to adjust in code vs simple function
> name change with 1:1 replacement.
>
> --
> --Kyle R. Stanley, Python Core Developer (what is a core dev?
> )
> *Pronouns: they/them **(why is my pronoun here?*
> 
> )
>
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/F52UKISVFFGBNCL2AZ4XVX2KL35O6ZNH/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/I6LJVGXIRNATRNAQG6RFMMPKXDANSBEL/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Serhiy Storchaka
28.11.21 17:13, Skip Montanaro пише:
>> That is not entirely true: 
>> https://github.com/python/cpython/pull/29639#issuecomment-974146979
> 
> The only places I've seen "if 0:" or "if False:" in live code was for
> debugging. Optimizing that hardly seems necessary. In any case, the
> original comment was about comparisons of two constants. I suppose
> sweeping up all of that into a constant expression folding/elimination
> step performed on the AST and/or during peephole optimization would
> cover both cases.

"if 0:" and "if False:" is already optimized by the compiler. The OP
proposes to optimize "2 < 1", and I cannot imagine any use case for this.

___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/ZJPTMHWPTPWC6Q4ZKWJB5CY6LURQ75PM/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Serhiy Storchaka
27.11.21 15:47, Jeremiah Vivian пише:
> Many operations involving two literals are optimized (to a certain level). So 
> it sort of surprises me that literal comparisons are not optimized and 
> literal contains only convert the right operand to a constant if possible. 
> I'd like to implement optimizations for these especially for the literal 
> contains. There is a TODO in the ast optimizer for literal comparisons as 
> well, and that's another reason I would like to have these added.

Only these operations were optimized which were necessary or very
useful. The Python parser produces only sign-less numbers, so it was
necessary to optimize unary minus to make -5 as fast as 5. Binary plus
and minus are necessary to make complex constants. "**" and "<<" are
often used in expressions for limits, masks and flags (5*10**6, 2**32-1,
1<<12). There is a benefit of computing such constants at compile time.
"*" and "/" can be used to create self-documenting constats too
(24*60*60, 1/3). And finally, indexing of bytes objects gets an ASCII
code of the character (b'a'[0]), it is useful too.

___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/73G2WZDTKG57JKKUVOCFOIDEL3D75W4O/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Eric V. Smith

> On Nov 28, 2021, at 3:03 PM, Serhiy Storchaka  wrote:
> 
> 28.11.21 17:13, Skip Montanaro пише:
>>> That is not entirely true: 
>>> https://github.com/python/cpython/pull/29639#issuecomment-974146979
>> 
>> The only places I've seen "if 0:" or "if False:" in live code was for
>> debugging. Optimizing that hardly seems necessary. In any case, the
>> original comment was about comparisons of two constants. I suppose
>> sweeping up all of that into a constant expression folding/elimination
>> step performed on the AST and/or during peephole optimization would
>> cover both cases.
> 
> "if 0:" and "if False:" is already optimized by the compiler. The OP
> proposes to optimize "2 < 1", and I cannot imagine any use case for this.

I agree. I suggest we don’t add this optimization. 

Eric
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/JP6FF2RHDQSIOS6ZAI45S7X6UXWGPBKR/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Rob Cliffe via Python-Dev
I am slightly surprised that it seems to be *easier* to fold selected 
constant expressions than to have more generic code to fold them all.

Or at least, all those that don't contain containers, such as
    1 in [0,1,2]
Rob Cliffe

On 28/11/2021 21:10, Eric V. Smith wrote:

On Nov 28, 2021, at 3:03 PM, Serhiy Storchaka  wrote:

28.11.21 17:13, Skip Montanaro пише:

That is not entirely true: 
https://github.com/python/cpython/pull/29639#issuecomment-974146979

The only places I've seen "if 0:" or "if False:" in live code was for
debugging. Optimizing that hardly seems necessary. In any case, the
original comment was about comparisons of two constants. I suppose
sweeping up all of that into a constant expression folding/elimination
step performed on the AST and/or during peephole optimization would
cover both cases.

"if 0:" and "if False:" is already optimized by the compiler. The OP
proposes to optimize "2 < 1", and I cannot imagine any use case for this.

I agree. I suggest we don’t add this optimization.

Eric
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/JP6FF2RHDQSIOS6ZAI45S7X6UXWGPBKR/
Code of Conduct: http://python.org/psf/codeofconduct/


___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/LD3XHINO7VPDE5EMNFD5ON4FQIJLY4DI/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Christopher Barker
I will frequently do simple computation with literals to make my code more
clear:

t = 2 * 3600  # 2 hours in seconds

But I see no need to optimize this kind of thing -- it would never be in a
tight loop.

-CHB


On Sun, Nov 28, 2021 at 3:06 PM Rob Cliffe via Python-Dev <
python-dev@python.org> wrote:

> I am slightly surprised that it seems to be *easier* to fold selected
> constant expressions than to have more generic code to fold them all.
> Or at least, all those that don't contain containers, such as
>  1 in [0,1,2]
> Rob Cliffe
>
> On 28/11/2021 21:10, Eric V. Smith wrote:
> >> On Nov 28, 2021, at 3:03 PM, Serhiy Storchaka 
> wrote:
> >>
> >> 28.11.21 17:13, Skip Montanaro пише:
>  That is not entirely true:
> https://github.com/python/cpython/pull/29639#issuecomment-974146979
> >>> The only places I've seen "if 0:" or "if False:" in live code was for
> >>> debugging. Optimizing that hardly seems necessary. In any case, the
> >>> original comment was about comparisons of two constants. I suppose
> >>> sweeping up all of that into a constant expression folding/elimination
> >>> step performed on the AST and/or during peephole optimization would
> >>> cover both cases.
> >> "if 0:" and "if False:" is already optimized by the compiler. The OP
> >> proposes to optimize "2 < 1", and I cannot imagine any use case for
> this.
> > I agree. I suggest we don’t add this optimization.
> >
> > Eric
> > ___
> > Python-Dev mailing list -- python-dev@python.org
> > To unsubscribe send an email to python-dev-le...@python.org
> > https://mail.python.org/mailman3/lists/python-dev.python.org/
> > Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/JP6FF2RHDQSIOS6ZAI45S7X6UXWGPBKR/
> > Code of Conduct: http://python.org/psf/codeofconduct/
>
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/LD3XHINO7VPDE5EMNFD5ON4FQIJLY4DI/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/NJWCKNV4ULEBHSLR44G3HNVROE4IAM47/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Eric V. Smith

On 11/28/2021 7:52 PM, Christopher Barker wrote:
I will frequently do simple computation with literals to make my code 
more clear:


t = 2 * 3600  # 2 hours in seconds


That is optimized as you'd hope. Tested in 3.8:

>>> dis.dis("t = 2 * 3600")
  1   0 LOAD_CONST   0 (7200)
  2 STORE_NAME   0 (t)
  4 LOAD_CONST   1 (None)
  6 RETURN_VALUE

Eric



But I see no need to optimize this kind of thing -- it would never be 
in a tight loop.


-CHB


On Sun, Nov 28, 2021 at 3:06 PM Rob Cliffe via Python-Dev 
 wrote:


I am slightly surprised that it seems to be *easier* to fold selected
constant expressions than to have more generic code to fold them all.
Or at least, all those that don't contain containers, such as
 1 in [0,1,2]
Rob Cliffe

On 28/11/2021 21:10, Eric V. Smith wrote:
>> On Nov 28, 2021, at 3:03 PM, Serhiy Storchaka
 wrote:
>>
>> 28.11.21 17:13, Skip Montanaro пише:
 That is not entirely true:
https://github.com/python/cpython/pull/29639#issuecomment-974146979
>>> The only places I've seen "if 0:" or "if False:" in live code
was for
>>> debugging. Optimizing that hardly seems necessary. In any
case, the
>>> original comment was about comparisons of two constants. I suppose
>>> sweeping up all of that into a constant expression
folding/elimination
>>> step performed on the AST and/or during peephole optimization
would
>>> cover both cases.
>> "if 0:" and "if False:" is already optimized by the compiler.
The OP
>> proposes to optimize "2 < 1", and I cannot imagine any use case
for this.
> I agree. I suggest we don’t add this optimization.
>
> Eric
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at

https://mail.python.org/archives/list/python-dev@python.org/message/JP6FF2RHDQSIOS6ZAI45S7X6UXWGPBKR/
> Code of Conduct: http://python.org/psf/codeofconduct/

___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at

https://mail.python.org/archives/list/python-dev@python.org/message/LD3XHINO7VPDE5EMNFD5ON4FQIJLY4DI/
Code of Conduct: http://python.org/psf/codeofconduct/



--
Christopher Barker, PhD (Chris)

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython

___
Python-Dev mailing list --python-dev@python.org
To unsubscribe send an email topython-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived 
athttps://mail.python.org/archives/list/python-dev@python.org/message/NJWCKNV4ULEBHSLR44G3HNVROE4IAM47/
Code of Conduct:http://python.org/psf/codeofconduct/___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/YEG3B44GJRHACEB4U6U2VAHT5E2SVXTO/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread Chris Angelico
On Mon, Nov 29, 2021 at 10:11 AM Rob Cliffe via Python-Dev
 wrote:
>
> I am slightly surprised that it seems to be *easier* to fold selected
> constant expressions than to have more generic code to fold them all.
> Or at least, all those that don't contain containers, such as
>  1 in [0,1,2]

This is optimized to a tuple rather than a list (and if you used a set
instead of a list, it'd be optimized to a frozenset), but the 'in'
comparison isn't optimized. The common case where it's "x in [0,1,2]"
is optimized as far as it can be.

ChrisA
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/KV7E4ALZLNY7BNMCNDVLUZHPORRRMRCC/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Optimizing literal comparisons and contains

2021-11-28 Thread MRAB

On 2021-11-29 00:52, Christopher Barker wrote:
I will frequently do simple computation with literals to make my code 
more clear:


t = 2 * 3600  # 2 hours in seconds

But I see no need to optimize this kind of thing -- it would never be in 
a tight loop.


The suggestion was specifically about optimising comparison of literals 
such as 1 < 2, which is not done at present, and the objection is 
basically YAGNI - that kind of thing is just too rare to be worth it.

___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/2VS4ZPFYAYVOG4BBHRWAFIEH7CU62X4B/
Code of Conduct: http://python.org/psf/codeofconduct/