Terry J. Reedy <tjre...@udel.edu> added the comment:

I think this proposal should be rejected for three reasons.

1. I believe the idea is faulty in that it can only work if the single source 
iterable *has* a known length. The compiler cannot, in general, determine that 
and in practice seldom would be able to. For a comprehension within a function, 
the source typically is or depends on a passed arg. What happens if you replace 
'range(10000)' with 'iter(range(10000))' in your patched version and rerun?

As I remember, Guido has rejected the idea of iterators having length 
information because in general it is not possible.

2. It adds an opcode for an extremely limited case. In 3.x, there are list, 
set, dict, and generator expression-comprehensions. Many 2.x uses of list 
comprehensions are (can be, increasingly will be) replaced by one of the 
others. In particular, lists long enough for there to be a real time saving 
tend to be replaced by generator expressions if possible.

3. The relative time saving in this limited case is at best 16% (.9/5.7) in a 
toy 2.7 example. I suspect it would be less in the more complex 3.x 
implementation and know it would be less in any realistic example with a real, 
slower target expression (at minimum try '2*j+1' or 'float(j)') and a slower 
source producer (such as a file object). And to repeat, a source with millions 
of items will likely be processed an item at a time without creating an 
explicit list.

----------
nosy: +terry.reedy

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue14126>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to