[issue26722] Fold compare operators on constants (peephole)

2016-04-10 Thread Demur Rumed

Demur Rumed added the comment:

I submitted a patch years ago that addressses the ''x,y = 1, 2' case:
http://bugs.python.org/issue10648 & it was not met with enthusiasm

2016-04-10 5:08 GMT+00:00 Alexander Marshalov :

>
> Alexander Marshalov added the comment:
>
> Hi all, this is my first patch to Python.
> I'm interested in the performance of python code, I even worked on the
> development of the static optimizer based on modifications of the AST.
> I had a few ideas for improving peepholer (for example, the expression "x,
> y = 1, 2" according to my benchmarks is about 7-11% slower than the
> expression "x = 1; y = 2", this can be fixed by using a peepholer), but I
> already understood that it is not necessary to do it.
> Thanks for the clarification, I will continue to work towards
> AST-optimizations.
>
> --
>
> ___
> Python tracker 
> 
> ___
>

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26722] Fold compare operators on constants (peephole)

2016-04-09 Thread Alexander Marshalov

Alexander Marshalov added the comment:

Hi all, this is my first patch to Python.
I'm interested in the performance of python code, I even worked on the 
development of the static optimizer based on modifications of the AST.
I had a few ideas for improving peepholer (for example, the expression "x, y = 
1, 2" according to my benchmarks is about 7-11% slower than the expression "x = 
1; y = 2", this can be fixed by using a peepholer), but I already understood 
that it is not necessary to do it. 
Thanks for the clarification, I will continue to work towards AST-optimizations.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26722] Fold compare operators on constants (peephole)

2016-04-09 Thread Nick Coghlan

Nick Coghlan added the comment:

Nice work on getting this running, Alexander. However, as Victor and Raymond 
noted, we're looking to head in a different direction with our bytecode 
optimisation efforts, which is to better support pluggable AST level 
optimisations that can make more assumptions about the runtime environment.

If this is a topic you'd like to explore further, then in addition to Victor's 
FAT Python project, you may also be interested in his proposals to add some 
supporting infrastructure for that to Python 3.6:

* Dict versioning: https://www.python.org/dev/peps/pep-0509/
* Function specialisation: https://www.python.org/dev/peps/pep-0510/
* Code transformers: https://www.python.org/dev/peps/pep-0511/

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

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26722] Fold compare operators on constants (peephole)

2016-04-09 Thread Raymond Hettinger

Raymond Hettinger added the comment:

AFAICT, the cases the OP listed would be rarely found in real code. 

Victor is correct is saying that we want to limit the scope of the peepholer to 
the most useful cases.  

He is also correct in saying that we've long desired constant folding to be 
moved upstream to the AST and don't want to go further down the path of doing 
more work at the bytecode level.  Ideally, the only optimizations at the 
peephole level would be limited to rejuggling opcodes into cheaper execution 
sequences without regard to higher level object semantics.

I recommend rejecting this and suggesting that more effort be focused on the 
AST optimizations.

--
nosy: +rhettinger
priority: normal -> low

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26722] Fold compare operators on constants (peephole)

2016-04-09 Thread STINNER Victor

STINNER Victor added the comment:

> Do you have any numbers on how common constant comparisons are in real code?

In my experience, it almost never occur in real application. But it's common 
when you start with a constant propogation optimization:

* https://faster-cpython.readthedocs.org/optimizations.html#constant-propagation
* 
https://fatoptimizer.readthedocs.org/en/latest/optimizations.html#constant-propagation

If you extend constant propagation to things like os.name, it's even more 
common, but it requires to specialize the code, to disable optimization if 
os.name is modified (that's one feature provided by FAT Python).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26722] Fold compare operators on constants (peephole)

2016-04-09 Thread STINNER Victor

STINNER Victor added the comment:

Hi, it looks like the author of the peephole optimizer is Raymond Hettinger and 
he doesn't look to want to handle too many cases, he prefers to keep the code 
simple.

FYI I reimplemented recently the peephole optimizer in pure Python as part of 
the bytecode project:
https://bytecode.readthedocs.org/en/latest/peephole.html

I didn't write it to replace the C implementation, it was more a tool to 
discuss modifying bytecode (when discussing the PEP 511).

More generally, there is an ongoging discussion of rewriting the peephole 
optimizer to work on the AST rather than working on the Python code. The FAT 
Python implements that in pure Python:
https://faster-cpython.readthedocs.org/fat_python.html

FAT Python is more than a peephole optimizer, it's more a framework to 
implement more optimizations. Well, take a look.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26722] Fold compare operators on constants (peephole)

2016-04-09 Thread Demur Rumed

Demur Rumed added the comment:

Do you have any numbers on how common constant comparisons are in real code?

--
nosy: +Demur Rumed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26722] Fold compare operators on constants (peephole)

2016-04-09 Thread SilentGhost

Changes by SilentGhost :


--
nosy: +benjamin.peterson, brett.cannon, georg.brandl, haypo, ncoghlan, 
yselivanov
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26722] Fold compare operators on constants (peephole)

2016-04-09 Thread Alexander Marshalov

New submission from Alexander Marshalov:

Missed peephole optimization:
   1 > 2  ->  False
   3 < 4  ->  True
   5 == 6  ->  False
   6 != 7  ->  True
   7 >= 8  ->  False
   8 <= 9  ->  True
   10 is 11 -> False
   12 is not 13  ->  True
   14 in (15, 16, 17)  ->  False
   18 not in (19, 20, 21)  ->  True

--
components: Interpreter Core
files: peephole_compareops.patch
keywords: patch
messages: 263089
nosy: amper
priority: normal
severity: normal
status: open
title: Fold compare operators on constants (peephole)
type: enhancement
versions: Python 3.6
Added file: http://bugs.python.org/file42414/peephole_compareops.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com