[pypy-dev] Question about byte-code hacking

Steven D'Aprano steve at pearwood.info
Fri Sep 23 11:27:44 CEST 2011


Benjamin Peterson wrote:
> 2011/9/23 Steven D'Aprano <steve at pearwood.info>:
>> Hi guys,
>>
>> Over on the python-ideas mailing list, there is a long thread about the
>> default argument hack in functions, used for micro-optimizations,
>> early-binding, and monkey-patching. Various alternatives are being argued
>> about. One proposal put forward involves bytecode manipulations to change
>> global lookups to local so that one could have a decorator that "injects" a
>> value into a copy of the function.
>>
>>
>> What's the PyPy position on bytecode hacking? Good, bad, evil, don't mind
>> either way?
> 
> First of all, it's going to be implementation defined. So, you can't
> expect *any* bytecode you create on one VM to work on another.
> Secondly, it's useless for speed when you have a JIT.

I don't expect that the same bytecode would work on multiple 
implementations. Obviously each implementation would either need its own 
bytecode manipulation, or simply refuse to support it.

Regardless of whether it is useless for speed or not, it is legal 
syntax. Default arguments are also used for early binding, which has 
nothing to do with speed.

So the question is: would it be a burden for PyPy to make any guarantees 
about the stability of bytecode?



-- 
Steven



More information about the pypy-dev mailing list