[New-bugs-announce] [issue26549] co_stacksize is calculated from unoptimized code

Antti Haapala report at bugs.python.org
Sat Mar 12 17:45:45 EST 2016


New submission from Antti Haapala:

When answering a question on StackOverflow, I noticed that a function that only loads a constant tuple to a local variable still has a large `co_stacksize` as if it was built with BUILD_TUPLE.

e.g.

    >>> def foo():
    ...     a = (1,2,3,4,5,6,7,8,9,10)
    ...
    >>> foo.__code__.co_stacksize
    10
    >>> dis.dis(foo)
      2           0 LOAD_CONST              11 ((1, 2, 3, 4, 5, 6, 7, 8, 9, 10))
                  3 STORE_FAST               0 (a)
                  6 LOAD_CONST               0 (None)
                  9 RETURN_VALUE

I suspect it is because in the `makecode` the stack usage is calculated from the unoptimized assembler output instead of the actual optimized bytecode. I do not know if there is any optimization that would increase the stack usage, but perhaps it should be calculated from the resulting output.

----------
components: Interpreter Core
messages: 261668
nosy: ztane
priority: normal
severity: normal
status: open
title: co_stacksize is calculated from unoptimized code
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26549>
_______________________________________


More information about the New-bugs-announce mailing list