Optimized bytecode in exec statement

H

Hermann Lauer

Dear All,

while trying to optimize some unpack operations with self compiling
code I wondered howto invoke the optimization in the exec statement.
Even starting with -O or -OO yields in Python 2.5.2 the same dis.dis code, which
is appended below.

My interest would be to reduce the LOAD_FAST ops of "s" with DUP_TOP on the stack
(are there hash lookups behind those ?) and of course to optimize the integer
arithmetics following below (removing +-0 etc).

Thanks for any ideas,
greetings
Hermann


class fa(struct.Struct):
def __init__(s):
super(fa,s).__init__('d')

def __call__(s,):
return s.unpack_from(s.buf,5392+(((s.lastrow()-0)%2880)*3+0)*8)[0]
7 0 LOAD_FAST 0 (s)
3 LOAD_ATTR 0 (unpack_from)
6 LOAD_FAST 0 (s)
9 LOAD_ATTR 1 (buf)
12 LOAD_CONST 1 (5392)
15 LOAD_FAST 0 (s)
18 LOAD_ATTR 2 (lastrow)
21 CALL_FUNCTION 0
24 LOAD_CONST 2 (0)
27 BINARY_SUBTRACT
28 LOAD_CONST 3 (2880)
31 BINARY_MODULO
32 LOAD_CONST 4 (3)
35 BINARY_MULTIPLY
36 LOAD_CONST 2 (0)
39 BINARY_ADD
40 LOAD_CONST 5 (8)
43 BINARY_MULTIPLY
44 BINARY_ADD
45 CALL_FUNCTION 2
48 LOAD_CONST 2 (0)
51 BINARY_SUBSCR
52 RETURN_VALUE
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top