[Python-ideas] Disable all peephole optimizations

Steven D'Aprano steve at pearwood.info
Thu May 22 20:14:11 CEST 2014


On Thu, May 22, 2014 at 10:29:48AM -0700, Ethan Furman wrote:

> However, we could turn off optimizations by default, and then have -O 
> remove assertions /and/ turn on optimizations.
> 
> Which would still work nicely with .pyc and .pyo files as ... wait, let me 
> make a table:
> 
>  flag   |  optimizations     |  saved files
> --------+--------------------+--------------
>   none  |    none            |    none
> --------+--------------------+--------------
>   -O    | asserts removed    |   .pyc
>         | peephole, etc.     |
> --------+--------------------+--------------
>   -OO   | -O plus            |
>         | docstrings removed |   .pyo

I think we still want to cache byte code in .pyc files by default. 
Technically, yes, it's an optimization, but it's not the sort of 
optimization that makes a difference to debugging[1]. As I understand 
it, generating the parse tree is *extremely* expensive. Run python -v to 
see just how many modules would have to be parsed and compiled every 
single time without the cached .pyc files.


> That would certainly make the -O flags make more sense than they do now.  
> It would also emphasize the fact that assert is not for user data 
> verification.  ;)

:-)




[1] Except perhaps under very rare and unusual circumstances, but there 
are already mechanisms in place to disable the generation of .pyc files.

-- 
Steven


More information about the Python-ideas mailing list