On Wed, Jun 16, 2021 at 02:50:06PM +0000, Oliver Margetts wrote:

> Hi all, I came across the following performance issue with the sum function
> while summing lists: https://bugs.python.org/issue18305 It's been discussed
> previously in this list and other issues.

Did you actually use sum to concatenate lists in real code, or is this a 
theoretical issue?

What circumstances do you have where you want to concatenate a large 
number of lists and thought that sum was an appropriate way to do it?


[...]
> Having non-linear complexity is not a suitable way to discourage this
> behaviour though.

We didn't put non-linear complexity in as a way to discourage the use of 
sum. The non-linear complexity comes about as a natural consequence of 
the behaviour of lists, it is not a "passive-aggressive runtime".

There is no practical way for us to detect ahead of time all imaginable 
types where repeated addition has non-linear behaviour. And although sum 
was intended for use only with numbers, there is no *hard* rule in 
Python that people can't use functions for unintended purposes that make 
sense to them.

It may even be that there are people who consider the convenience of sum 
worth it even for lists, since quadratic runtime behaviour is still fast 
for small enough N. I sometimes use it myself, in the REPL, to merge a 
handful of lists. If it takes 100 ms instead of a microsecond, 
I don't even notice.

The performance error for strings should be considered an anomaly, not a 
feature to be extended to anything that could be used, or misused, with 
non-linear behaviour. At the very least, we would probably need to see 
evidence that this issue (poor performance) is a widespread problem 
before breaking code which works fine for small N.


-- 
Steve
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/FSD5TENDE4RLESDRPWN7WJ3WJMFPRASC/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to