New submission from Jeffrey Harper <jhar...@yapdc.com>: In Python 3.2, a tuple like (1,-2,3) will not be optimized into a constants at compile time. The tuple is built at run-time. Earlier versions of Python optimized these tuples at compile time.
Here's an example program. # test.py from dis import dis def x(): return (1,2,3) def y(): return (1,-2,3) print ("dis x:") dis(x) print() print("dis y:") dis(y) The compiler in 3.2rc3 produces code for function y() that builds the tuple at run-time while the tuple in x() is optimized at compile time. C:\tmp>c:\python32\python --version Python 3.2rc3 C:\tmp>c:\python32\python test.py dis x: 3 0 LOAD_CONST 4 ((1, 2, 3)) 3 RETURN_VALUE dis y: 4 0 LOAD_CONST 1 (1) 3 LOAD_CONST 4 (-2) 6 LOAD_CONST 3 (3) 9 BUILD_TUPLE 3 12 RETURN_VALUE However, under 3.1.3, the tuples in both functions are optimized at compile time. C:\tmp>c:\python31\python test.py dis x: 3 0 LOAD_CONST 4 ((1, 2, 3)) 3 RETURN_VALUE dis y: 4 0 LOAD_CONST 4 ((1, -2, 3)) 3 RETURN_VALUE Although the compiled code produced 3.2rc3 is correct, it is much slower than the code generated by 3.1.3. ---------- messages: 128795 nosy: jdharper priority: normal severity: normal status: open title: Negative tuple elements produce inefficient code. type: performance versions: Python 3.2 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue11244> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com