Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

> I was going to note that the algorithm Anthony has pursued here is the same 
> one we already use for the list constructor and list.extend(), but Inada-san 
> already pointed that out :)

And that optimization looks questionable to me. I tried to reduce an overhead 
for small lists, but this requires much more complex code and gives mixed 
results.

I am -1 for this optimization because it affects only one particular case 
(neither other kinds of comprehensions, nor generator expressions, nor list 
comprehensions with conditions) and even in this case it is small. It is 
possible to add a lot of other optimizations for other cases which will sped up 
them to 50% or 100%, but we do not do this, because every such optimization has 
a cost. It increases the amount of code which should be maintained and covered 
by tests, it adds small overhead in common cases to speed up an uncommon case, 
and increasing the code base can negatively affect surrounding code (just 
because the CPU cache and registers are used inappropriate and the compiler 
optimizes less important paths).

In addition, while this change speed up list comprehensions for long list, it 
slows down them for short lists. Short lists are more common.

----------

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

Reply via email to