[Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Fredrik Lundh
Raymond Hettinger wrote: Based on some ideas from Skip, I had tried transforming the likes of x in (1,2,3) into x in frozenset([1,2,3]). When applicable, it substantially simplified the generated code and converted the O(n) lookup into an O(1) step. There were substantial savings even if

Re: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Skip Montanaro
Based on some ideas from Skip, I had tried transforming the likes of x in (1,2,3) into x in frozenset([1,2,3]) Fredrik savings in what? time or bytecode size? constructed Fredrik micro-benchmarks, or examples from real-life code? Fredrik do we have any statistics on

RE: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Raymond Hettinger
I'm unclear why the list in for x in [1,2,3] or if x not in [1,2,3] can't fairly easily be recognized as a constant and just be placed in the constants array. That part got done (at least for the if-statement). The question is whether the type transformation idea should be carried a step

Re: [Python-Dev] Re: Prospective Peephole Transformation

2005-02-18 Thread Phillip J. Eby
At 04:45 PM 2/18/05 +0100, Fredrik Lundh wrote: Phillip J. Eby wrote: Only contains expressions are translated: if x in [1,2,3] currently turns into: if x in (1,2,3) and I'm proposing that it go one step further: if x in Seachset([1,2,3]) ISTM that whenever I use a constant

Re: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread M.-A. Lemburg
Raymond Hettinger wrote: Based on some ideas from Skip, I had tried transforming the likes of x in (1,2,3) into x in frozenset([1,2,3]). When applicable, it substantially simplified the generated code and converted the O(n) lookup into an O(1) step. There were substantial savings even if the set

[Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread Travis Oliphant
Hello again, There is a great discussion going on the numpy list regarding a proposed PEP for multidimensional arrays that is in the works. During this discussion as resurfaced regarding slicing with objects that are not IntegerType objects but that have a tp_as_number-nb_int method to convert

Re: [Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread Guido van Rossum
Would it be possible to change _PyEval_SliceIndex in ceval.c so that rather than throwing an error if the indexing object is not an integer, the code first checks to see if the object has a tp_as_number-nb_int method and calls it instead. I don't think this is the right solution; since

Re: [Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread Brett C.
Travis Oliphant wrote: Hello again, There is a great discussion going on the numpy list regarding a proposed PEP for multidimensional arrays that is in the works. During this discussion as resurfaced regarding slicing with objects that are not IntegerType objects but that have a

[Python-Dev] Fix _PyEval_SliceIndex (Take two)

2005-02-18 Thread Travis Oliphant
(More readable second paragraph) Hello again, There is a great discussion going on the numpy list regarding a proposed PEP for multidimensional arrays that is in the works. During this discussion a problem has resurfaced regarding slicing with objects that are not IntegerType objects but that

Re: [Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread David Ascher
On Fri, 18 Feb 2005 13:28:34 -0800, Guido van Rossum [EMAIL PROTECTED] wrote: Would it be possible to change _PyEval_SliceIndex in ceval.c so that rather than throwing an error if the indexing object is not an integer, the code first checks to see if the object has a

Re: [Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread Bob Ippolito
On Feb 18, 2005, at 4:36 PM, David Ascher wrote: On Fri, 18 Feb 2005 13:28:34 -0800, Guido van Rossum [EMAIL PROTECTED] wrote: Would it be possible to change _PyEval_SliceIndex in ceval.c so that rather than throwing an error if the indexing object is not an integer, the code first checks to see

Re: [Python-Dev] Windows Low Fragementation Heap yields speedup of ~15%

2005-02-18 Thread Evan Jones
On Thu, 2005-02-17 at 22:38, Tim Peters wrote: Then you allocate a small object, marked 's': bbbsfff Isn't the whole point of obmalloc is that we don't want to allocate s on the heap, since it is small? I guess s could be an object that might potentially

Re: [Python-Dev] Memory Allocator Part 2: Did I get it right?

2005-02-18 Thread Evan Jones
Sorry for taking so long to get back to this thread, it has been one of those weeks for me. On Feb 16, 2005, at 2:50, Martin v. Löwis wrote: Evan then understood the feature, and made it possible. This is very true: it was a very useful exercise. I can personally accept breaking the code that

Re: [Python-Dev] Fixing _PyEval_SliceIndex so that integer-like objects can be used

2005-02-18 Thread Travis Oliphant
Guido van Rossum wrote: Would it be possible to change _PyEval_SliceIndex in ceval.c so that rather than throwing an error if the indexing object is not an integer, the code first checks to see if the object has a tp_as_number-nb_int method and calls it instead. I don't think this is the

Re: [Python-Dev] Windows Low Fragementation Heap yields speedup of ~15%

2005-02-18 Thread Tim Peters
[Tim Peters] ... Then you allocate a small object, marked 's': bbbsfff [Evan Jones] Isn't the whole point of obmalloc No, because it doesn't matter what follows that introduction: obmalloc has several points, including exploiting the GIL, heuristics

Re: [Python-Dev] Windows Low Fragementation Heap yields speedup of ~15%

2005-02-18 Thread Evan Jones
On Feb 18, 2005, at 17:51, Tim Peters wrote: grow the list to its final size once, at the start (overestimating if you don't know for sure). Then instead of appending, keep an index to the next free slot, same as you'd do in C. Then the list guts never move, so if that doesn't yield the same

Re: [Python-Dev] Re: Re: Re: Prospective Peephole Transformation

2005-02-18 Thread Tim Peters
[Phillip J. Eby] Still, it's rather interesting that tuple.__contains__ appears slower than a series of LOAD_CONST and == operations, considering that the tuple should be doing basically the same thing, only without bytecode fetch-and- decode overhead. Maybe it's tuple.__contains__ that needs

RE: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread Raymond Hettinger
Wouldn't it help a lot more if the compiler would detect that (1,2,3) is immutable and convert it into a constant at compile time ?! Yes. We've already gotten it to that point: . . . Cool. Does that work for all tuples in the program ? It is limited to just tuples of constants

Re: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread Tim Peters
[Raymond Hettinger] ... The problem with the transformation was that it didn't handle the case where x was non-hashable and it would raise a TypeError instead of returning False as it should. I'm very glad you introduced the optimization of building small constant tuples at compile-time.

Re: [Python-Dev] Windows Low Fragementation Heap yields speedup of ~15%

2005-02-18 Thread Tim Peters
[Tim Peters] grow the list to its final size once, at the start (overestimating if you don't know for sure). Then instead of appending, keep an index to the next free slot, same as you'd do in C. Then the list guts never move, so if that doesn't yield the same kind of speedup without using

[Python-Dev] Proposal for a module to deal with hashing

2005-02-18 Thread Nick Coghlan
Gregory P. Smith wrote: fyi - i've updated the python sha1/md5 openssl patch. it now replaces the entire sha and md5 modules with a generic hashes module that gives access to all of the hash algorithms supported by OpenSSL (including appropriate legacy interface wrappers and falling back to the

RE: [Python-Dev] Prospective Peephole Transformation

2005-02-18 Thread Raymond Hettinger
I'm very glad you introduced the optimization of building small constant tuples at compile-time. IMO, that was a pure win. It's been out in the wild for a while now with no issues. I'm somewhat happy with it. the transformation isn't semantically correct on the face of it. Well that's

[Python-Dev] Requesting that a class be a new-style class

2005-02-18 Thread Nick Coghlan
This is something I've typed way too many times: Py class C(): File stdin, line 1 class C(): ^ SyntaxError: invalid syntax It's the asymmetry with functions that gets to me - defining a function with no arguments still requires parentheses in the definition statement, but

Re: [Python-Dev] builtin_id() returns negative numbers

2005-02-18 Thread Donovan Baarda
From: Armin Rigo [EMAIL PROTECTED] Hi Tim, On Thu, Feb 17, 2005 at 01:44:11PM -0500, Tim Peters wrote: 256 ** struct.calcsize('P') Now if you'll just sign and fax a Zope contributor agreement, I'll upgrade ZODB to use this slick trick wink. I hereby donate this line of code to

Re: [Python-Dev] license issues with profiler.py and md5.h/md5c.c

2005-02-18 Thread Donovan Baarda
From: Martin v. Löwis [EMAIL PROTECTED] Donovan Baarda wrote: This patch keeps the current md5c.c, md5module.c files and adds the following; _hashopenssl.c, hashes.py, md5.py, sha.py. [...] If all we wanted to do was fix the md5 module If we want to fix the licensing issues with the md5

Re: [Python-Dev] license issues with profiler.py and md5.h/md5c.c

2005-02-18 Thread Gregory P. Smith
On Fri, Feb 18, 2005 at 10:06:24AM +0100, Martin v. L?wis wrote: Donovan Baarda wrote: This patch keeps the current md5c.c, md5module.c files and adds the following; _hashopenssl.c, hashes.py, md5.py, sha.py. [...] If all we wanted to do was fix the md5 module If we want to fix the

Re: [Python-Dev] Requesting that a class be a new-style class

2005-02-18 Thread Alex Martelli
On 2005 Feb 19, at 06:03, Nick Coghlan wrote: This is something I've typed way too many times: Py class C(): File stdin, line 1 class C(): ^ SyntaxError: invalid syntax It's the asymmetry with functions that gets to me - defining a function with no arguments still requires