Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-12 Thread Terry Reedy
On 9/12/2012 3:36 AM, Serhiy Storchaka wrote: I personally would prefer a 2to3-like "modernizer" (as a separate utility and as plugins for the IDEs), which would have found some templates and offered replacing by a more modern, readable (and possibly effective) variant. The decision on the appli

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-12 Thread Maciej Fijalkowski
On Tue, Sep 11, 2012 at 2:57 PM, Nick Coghlan wrote: > On Tue, Sep 11, 2012 at 8:41 PM, Victor Stinner > 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 t

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-12 Thread Victor Stinner
>> 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'). > > But are you able to do enough static analysis to feel comfortable that > this is th

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-12 Thread Victor Stinner
2012/9/12 Serhiy Storchaka : >>> set([x for ...]) => {x for ...} >>> dict([(k, v) for ...]) => {k: v for ...} >>> dict((k, v) for ...) => {k: v for ...} >>> ''.join([s for ...]) => ''.join(s for ...) >>> a.extend([s for ...]) => a.extend(s for ...) >> >> These optimizations look correct. > > Actual

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-12 Thread Serhiy Storchaka
On 12.09.12 00:47, Victor Stinner wrote: x = x + [y] => x.append(y) x = x + [y, z] => x.extend([y, z]) It behaves differently if x is not a list, but str for example. Actually even worse. Transformations applicable only if x has not aliases. Pseudocode: if type(x) is list and refcount(x)

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-12 Thread Serhiy Storchaka
On 12.09.12 00:47, Victor Stinner wrote: set([x for ...]) => {x for ...} dict([(k, v) for ...]) => {k: v for ...} dict((k, v) for ...) => {k: v for ...} ''.join([s for ...]) => ''.join(s for ...) a.extend([s for ...]) => a.extend(s for ...) These optimizations look correct. Actually generator

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Guido van Rossum
On Tue, Sep 11, 2012 at 5:40 PM, Victor Stinner wrote: > 2012/9/11 Guido van Rossum : >> FWIW, I expect that there are few places where len() >> is actually used. > > I found one revelant example in the stdlib. > > if path.endswith('.dylib'): > yield path[:-len('.dylib'

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Victor Stinner
2012/9/11 Guido van Rossum : > FWIW, I expect that there are few places where len() > is actually used. I found one revelant example in the stdlib. if path.endswith('.dylib'): yield path[:-len('.dylib')] + suffix + '.dylib' else: yield path

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Victor Stinner
> i am a longtime Reader of this list and this is the first time i a dare to > speak up. > Apology in advance for any noise, silly comments and not posting to > python-ideas ;). Welcome! > Well how about implementing guards like in pypy? Guards would allow to generate specialized functions witho

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread larudwer
Hello, i am a longtime Reader of this list and this is the first time i a dare to speak up. Apology in advance for any noise, silly comments and not posting to python-ideas ;). Am 11.09.2012 12:41, schrieb Victor Stinner: I plan to implement other optimizations like unrolling loop or convert

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread MRAB
On 11/09/2012 22:46, Victor Stinner wrote: 2012/9/11 Nick Coghlan : 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. The version 0.3 has a known bug: "len=chr; print(len('A'))" is o

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Victor Stinner
>>> - frozenset("ab") | frozenset("bc") => frozenset("abc") > > That's a name lookup, too. Yes, and it is only optimized if the "builtin_funcs" feature is enabled explictly. > Except that evaluating something like '"abc" * constant' can eat up all > memory, imagine this code: > > KILL_MEMOR

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Victor Stinner
>> * Call builtin functions if arguments are constants. Examples: >> >>- len("abc") => 3 >>- ord("A") => 65 > > Does this mean transformation print("A") => None and output at compile time? Only a subset of builtin functions are called at compile time, and not with any constant value. See a

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Victor Stinner
2012/9/11 Nick Coghlan : > 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. The version 0.3 has a known bug: "len=chr; print(len('A'))" is optimized, whereas it should not. It is no

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Stefan Behnel
Serhiy Storchaka, 11.09.2012 20:48: > set([1, 2, 3]) => {1, 2, 3} > set([x for ...]) => {x for ...} > dict([(k, v) for ...]) => {k: v for ...} > dict((k, v) for ...) => {k: v for ...} > ''.join([s for ...]) => ''.join(s for ...) > a.extend([s for ...]) => a.extend(s for ...) > (f(x) for x in a) =>

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Stefan Behnel
Nick Coghlan, 11.09.2012 14:57: > On Tue, Sep 11, 2012 at 8:41 PM, Victor Stinner wrote: >> * Loop: replace range() with xrange() on Python 2, and list with >> tuple. Examples: >> >> - for x in range(n): ... => for x in xrange(n): ... >> - for x in [1, 2, 3]: ... => for x in (1, 2, 3): ... >

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Serhiy Storchaka
On 11.09.12 13:41, Victor Stinner wrote: Here are some progress on my astoptimizer project. If you are interested by the optimizer, run it on your own project or help me to implement more optimizations. http://pypi.python.org/pypi/astoptimizer https://bitbucket.org/haypo/astoptimizer It's a ve

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Guido van Rossum
On Tue, Sep 11, 2012 at 10:06 AM, MRAB wrote: > On 11/09/2012 13:06, Victor Stinner wrote: * Call builtin functions if arguments are constants. Examples: - len("abc") => 3 - ord("A") => 65 >>> >>> >>> Does it preserve python semantics? What if you change the len builti

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread MRAB
On 11/09/2012 13:06, Victor Stinner wrote: * Call builtin functions if arguments are constants. Examples: - len("abc") => 3 - ord("A") => 65 Does it preserve python semantics? What if you change the len builtin? This optimization is disabled by default (in the version 0.3), because built

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Nick Coghlan
On Tue, Sep 11, 2012 at 8:41 PM, Victor Stinner 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 m

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Victor Stinner
>> * Call builtin functions if arguments are constants. Examples: >> >> - len("abc") => 3 >> - ord("A") => 65 > > Does it preserve python semantics? What if you change the len builtin? This optimization is disabled by default (in the version 0.3), because builtin functions may be shadowed. Exa

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Maciej Fijalkowski
On Tue, Sep 11, 2012 at 12:41 PM, Victor Stinner wrote: > Hi, > > Here are some progress on my astoptimizer project. If you are interested by > the optimizer, run it on your own project or help me to implement more > optimizations. > > http://pypi.python.org/pypi/astoptimizer > https://bitbucket.o

Re: [Python-Dev] Release of astoptimizer 0.3

2012-09-11 Thread Christian Heimes
Am 11.09.2012 12:41, schrieb Victor Stinner: > Hi, > > Here are some progress on my astoptimizer project. If you are interested by > the optimizer, run it on your own project or help me to implement more > optimizations. Wow, that's an amazing list of optimizations. Keep up the good work! Christ