[issue45542] Using multiple comparison operators can cause performance issues

2021-10-20 Thread Maja


New submission from Maja :

For example:

def f(x):
return 1 < x < 3

will be slower than:

def f(x):
return 1 < x and x < 3

The first function will generate following bytecode:

  0 LOAD_CONST   1 (1)
  2 LOAD_FAST0 (x)
  4 DUP_TOP
  6 ROT_THREE
  8 COMPARE_OP   0 (<)
 10 JUMP_IF_FALSE_OR_POP18
 12 LOAD_CONST   2 (3)
 14 COMPARE_OP   0 (<)
 16 RETURN_VALUE
>>   18 ROT_TWO
 20 POP_TOP
 22 RETURN_VALUE

Performs unnecessary stack operations: duplicates x, rotates 3 items for no 
reason, then re-rotates 2 items and pops a value. This is fine if the value in 
the middle was more complex and needed to be duplicated rather than 
recalculated, which would be definitely slower, but for simpler values like 
names or constants, it's actually bad. The bytecode for the first function 
should look the same as second one which is:

  0 LOAD_CONST   1 (1)
  2 LOAD_FAST0 (x)
  4 COMPARE_OP   0 (<)
  6 JUMP_IF_TRUE_OR_POP 14
  8 LOAD_FAST0 (x)
 10 LOAD_CONST   2 (3)
 12 COMPARE_OP   0 (<)
>>   14 RETURN_VALUE

--
components: Interpreter Core
messages: 404508
nosy: akuvfx
priority: normal
severity: normal
status: open
title: Using multiple comparison operators can cause performance issues
type: performance
versions: Python 3.11

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



[issue45542] Using multiple comparison operators can cause performance issues

2021-10-20 Thread Maja


Change by Maja :


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

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



[issue25450] Save path automatically choses C:\Windows\system32

2015-10-20 Thread Maja Tomic

New submission from Maja Tomic:

I'm teaching kids to code in Python. Today we had two boys, one with Windows 8, 
the other one with Windows 10. In both cases Python 3.5 was installed and the 
automatic path where files are saved was C:\Windows\system32. This wasn't 
possible, since it cannot be written to. Yet, the boys tried to save files to 
it. 

In the Windows 8-case the file did not get saved. Yet, IDLE still refered to 
the file as having an error (it couldn't find the turtle package because the 
file was called turtle.py - we got that right eventually). Even after 
reinstalling Python it still refered to the non-existing file and the error in 
it. 
We changed the path and it solved the problem. Hope this can be fixed.

--
components: Installation
messages: 253257
nosy: Maja Tomic
priority: normal
severity: normal
status: open
title: Save path automatically choses C:\Windows\system32
type: behavior
versions: Python 3.5

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