[Python-ideas] Disable all peephole optimizations

Nick Coghlan ncoghlan at gmail.com
Wed May 21 13:41:45 CEST 2014


On 21 May 2014 21:06, "Ned Batchelder" <ned at nedbatchelder.com> wrote:
> ** Implementation
>
> Although it may seem like a big change to be able to disable the
optimizer, the heart of it is quite simple.  In compile.c is the only call
to PyCode_Optimize.  That function takes a string of bytecode and returns
another.  If we skip that call, the peephole optimizer is disabled.
>
> ** User Interface
>
> Unfortunately, the -O command-line switch does not lend itself to a new
value that means, "less optimization than the default."  I propose a new
switch -P, to control the peephole optimizer, with a value of -P0 meaning
no optimization at all.  The PYTHONPEEPHOLE environment variable would also
control the option.

Since this is a CPython specific thing, a -X named command line option
would be more appropriate.

>
> There are about a dozen places internal to CPython where optimization
level is indicated with an integer, for example, in
Py_CompileStringObject.  Those uses also don't allow for new values
indicating less optimization than the default: 0 and -1 already have
meanings.  Unless we want to start using -2 for less that the default.  I'm
not sure we need to provide for those values, or if the PYTHONPEEPHOLE
environment variable provides enough control.

I assume you want the environment variable so the setting can be inherited
by subprocesses?

Cheers,
Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140521/6cc2c044/attachment.html>


More information about the Python-ideas mailing list