1

I hear that python functions are compiled to bytecode as soon as they are defined.

But, according to this post, only very few optimizations are made during this step.

So, when I define this python function:

def dummy(obj):
    i = obj
    a = i
    o = a
    return o

is it not optimized to / interpreted as / equivalent to:

def dummy(obj):
    return obj

by the interpreter/compiler.

As for objects member/dict access, this function:

def dummy(obj):
    res = obj.member + obj.member ** 2
    return [res, obj.member]

is not optimized to:

def dummy(obj):
    mb = obj.member
    return [mb + mb ** 2, mb]

Since python does not perform this simple job, which seems automatable yet non-trivial, are there tools to do this?

iago-lito
  • 3,098
  • 3
  • 29
  • 54
  • @Kasramvd I've moved the focus towards alternative tools, which are not adressed in the duplicate. Is it enough for the question to be reopened? – iago-lito Jun 08 '18 at 12:36
  • It's mentioned in that answer that this behavior is specifically attributed to a particular implementation. Therefore, if you look for such tools you may be able to find it in other implementations such as PyPy, Jython, etc. – Mazdak Jun 08 '18 at 12:52
  • @Kasramvd Okay, thanks :) Do I close this post then? – iago-lito Jun 08 '18 at 12:54
  • It's already closed you can delete it if you want tho. – Mazdak Jun 08 '18 at 12:56

0 Answers0