[Python-Dev] Release of astoptimizer 0.3

Victor Stinner victor.stinner at gmail.com
Wed Sep 12 02:40:59 CEST 2012

2012/9/11 Guido van Rossum <guido at python.org>:
> FWIW, I expect that there are few places where len(<constant string>)
> is actually used.

I found one revelant example in the stdlib.

            if path.endswith('.dylib'):
                yield path[:-len('.dylib')] + suffix + '.dylib'
                yield path + suffix

Cool, I'm not the only developer too lazy to copy/paste len('suffix')
in a Python interpreter and then copy/paste the result in my code :-)

"if text.endswith('suffix'): ... text[:-len('suffix')] ..." is a
common pattern in my code.

> However I expect it to be quite common for ord(),
> where the same reasoning applies.

Projects using the same code base for Python 2 and Python 3 contain a
lot of inefficient code. For example, using the six library, a simple
Unicode literal strings becomes a function code: u('unicode').

I expect that astoptimizer will be able to remove (or at least
reduce!) the overhead of the six library and all checks on the Python
version ("if PYTHON3: ... else: ...").


More information about the Python-Dev mailing list