4 ms·
I thought that problem got fixed a few releases ago. Maybe 3.7, when some of the peephole optimizer logic was moved to the AST? At the very least, I can't repr
by eesmith 6y ago
I thought that problem got fixed a few releases ago. Maybe 3.7, when some of the peephole optimizer logic was moved to the AST?
At the very least, I can't reproduce it.
% cat tmp.py
(1<<19**8,)*4**7
% python -m compileall tmp.py
% ls -l __pycache__/tmp.cpython-39.pyc
-rw-r--r-- 1 eesmith admin 167 Feb 16 12:21 __pycache__/tmp.cpython-39.pyc
Python 3.6 generates a 144 byte file. One of the comments says it caused a problem in Python 3.3.5.
Another peephole optimizer gotcha that caused problems with older Pythons is at https://bugs.python.org/issue30416 https://bugs.python.org/issue30416 :
def tuple20():
return ((((((((1,)*20,)*20,)*20,)*20,)*20,)*20,)*20,)*20
If you have Python 2.7 hanging about, try simply defining that function - you can't even ^C it!
- chias 6y agoI am also unable to reproduce it (Python 3.8.5)
- jwilk 6y agoI can reproduce it with Python 3.5, but indeed not with 3.6.
- PartiallyTyped 6y agoI can't reproduce in 2.7.16 and 3.7 either. The tuple20 is an interesting one, using lists instead of tuples it doesn't explode in size, at least in 2.7
- eesmith 6y agoThat's because the peephole optimizer only looks at constants, and lists aren't constant while tuples are. It doesn't explode in size. The peephole optimizer is checking for uniqueness, via a dict, and evaluating hash() of that constant takes a very long time.