Mailing List Archive

[issue45907] Optimize literal comparisons and contains
New submission from theeshallnotknowethme <nohackingofkrowten@gmail.com>:

Most operations with literals are optimized as well, so why shouldn't the comparison/contain operators be? I created a new bug report for it because of this fact and the TODO in the `fold_compare` function in `Python/ast_opt.c`.

----------
components: Interpreter Core
messages: 407114
nosy: February291948
priority: normal
severity: normal
status: open
title: Optimize literal comparisons and contains
type: performance
versions: Python 3.11

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue45907>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue45907] Optimize literal comparisons and contains [ In reply to ]
Change by theeshallnotknowethme <nohackingofkrowten@gmail.com>:


----------
keywords: +patch
pull_requests: +28042
stage: -> patch review
pull_request: https://github.com/python/cpython/pull/29810

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue45907>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue45907] Optimize literal comparisons and contains [ In reply to ]
Raymond Hettinger <raymond.hettinger@gmail.com> added the comment:

This PR looks to be the same as one that was recently rejected.

Compare:
https://github.com/python/cpython/pull/29639/files
https://github.com/python/cpython/pull/29810/files

See discussion at:
https://bugs.python.org/issue45843

----------
nosy: +BTaskaya, pablogsal, rhettinger, serhiy.storchaka

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue45907>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue45907] Optimize literal comparisons and contains [ In reply to ]
theeshallnotknowethme <nohackingofkrowten@gmail.com> added the comment:

It doesn't seem to make sense why other operations on literals are optimized but these particular ones aren't optimized (much).

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue45907>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue45907] Optimize literal comparisons and contains [ In reply to ]
theeshallnotknowethme <nohackingofkrowten@gmail.com> added the comment:

If this bug report isn't accepted, for how long would the TODO remain in `Python/ast_opt.c`?

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue45907>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue45907] Optimize literal comparisons and contains [ In reply to ]
Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment:

> It doesn't seem to make sense why other operations on literals are optimized but these particular ones aren't optimized (much).

The existing optimizer optimizes the following cases (note that the parser does not produce negative or complex numbers, they are created by the optimizer):

-1
1-2j
1/3
16*1024
2**32-1
1<<12
b'a'[0]

They all are extremely common. Virtually every Python file contain some of such expressions, and they are often used in loops. In contrary, it is difficult to find any example of using comparison operations with all constant operands.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue45907>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue45907] Optimize literal comparisons and contains [ In reply to ]
theeshallnotknowethme <nohackingofkrowten@gmail.com> added the comment:

List and sets as right operands in literal contains are optimized to constant tuples and frozensets, and I'd like to take this optimization a step further.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue45907>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue45907] Optimize literal comparisons and contains [ In reply to ]
Batuhan Taskaya <isidentical@gmail.com> added the comment:

We just rejected the same issue 2 days ago. If you feel very strong about this; instead of creating new ticket in the same place, you might want to try python-dev instead.

Re: the todo comment, feel free to send a patch that removes it. I don't thank that is still applicable.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue45907>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue45907] Optimize literal comparisons and contains [ In reply to ]
Pablo Galindo Salgado <pablogsal@gmail.com> added the comment:

I agree with Serhiy and Batuhan. Please reach to python-dev of you really want to pursue this even after what has been already discussed.

----------
resolution: -> rejected
stage: patch review -> resolved
status: open -> closed

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue45907>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue45907] Optimize literal comparisons and contains [ In reply to ]
Pablo Galindo Salgado <pablogsal@gmail.com> added the comment:

On the other hand, we can probably just remove the TODO

----------

_______________________________________
Python tracker <report@bugs.python.org>
<https://bugs.python.org/issue45907>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com