[Python-ideas] More compact bytecode

Yury Selivanov yselivanov.ml at gmail.com
Fri Feb 5 17:46:31 EST 2016


Serhiy, Victor, Andrew,

What do you think about turning constant slice objects into actual 
constants?

Right now:

def a(): return a[:1]
dis.dis(a)
   1           0 LOAD_GLOBAL              0 (a)
               3 LOAD_CONST               0 (None)
               6 LOAD_CONST               1 (1)
               9 BUILD_SLICE              2
              12 BINARY_SUBSCR
              13 RETURN_VALUE


With this optimization we could just have:

   1           0 LOAD_GLOBAL              0 (a)
               3 LOAD_CONST               0 (:1)
               6 BINARY_SUBSCR
               7 RETURN_VALUE

Yury


More information about the Python-ideas mailing list