[Python-Dev] Release of astoptimizer 0.3

Maciej Fijalkowski fijall at gmail.com
Wed Sep 12 16:04:03 CEST 2012

On Tue, Sep 11, 2012 at 2:57 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Tue, Sep 11, 2012 at 8:41 PM, Victor Stinner
> <victor.stinner at gmail.com> wrote:
>> * Call builtin functions if arguments are constants. Examples:
>>   - len("abc") => 3
>>   - ord("A") => 65
> This is fine in an external project, but should never be added to the
> standard library. The barrier to semantic changes that break
> monkeypatching should be high.
> Yes, this is frustrating as it eliminates a great many interesting
> static optimisations that are *probably* OK. That's one of the reasons
> why PyPy uses tracing - it can perform these optimisations *and* still
> include the appropriate dynamic checks.
> However, the double barrier of third party module + off by default is
> a suitable activation barrier for ensuring people know that what
> they're doing is producing bytecode that doesn't behave like standard
> Python any more (e.g. tests won't be able to shadow builtins or
> optimised module references). Optimisations that break the language
> semantics are heading towards the same territory as the byteplay and
> withhacks modules (albeit not as evil internally).

The third (and the most important) barrier is that constant folding
len("abc") is essentially useless. You can do some optimizations that
are sound, at probably a great deal of complexity, if you maintain all
the places that constant folded stuff and change them if you shadow a
builtin. This approach is done in PyPy for example in a more
systematic way (by invalidating the assembler).

Anyway, since this is, in it's current shape clearly not designed to
preserve the semantics of python at all, is the discussion of this
package on-topic for python-dev? More so than say discussing Cython or
Numba or any other kind-of-python-but-not-quite project?


More information about the Python-Dev mailing list