This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients alex, serhiy.storchaka, vstinner
Date 2016-04-22.12:12:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1461327160.24.0.621419084727.issue26828@psf.upfronthosting.co.za>
In-reply-to
Content
When I compared the performance of filter() and map() between Python 2.7 and 3.4, I noticed a huge performance drop in Python 3!
http://bugs.python.org/issue26814#msg264003

I didn't analyze yet exactly why Python 3 is so much slower (almost 100% slower for the case of fitler!). Maybe it's because filter() returns a list on Python 2, whereas filter() returns an iterator on Python 3.

In Python 2, filter() and map() use _PyObject_LengthHint(seq, 8) to create the result list. Why don't we do the same in Python 3?

filter.__length_hint__() and map.__length_hint__() would return seq.__length_hint__() of the input sequence, or return 8. It's a weak estimation, but it can help a lot of reduce the number of realloc() when the list is slowly growing.

See also the PEP 424 -- A method for exposing a length hint.

Note: the issue #26814 (fastcall) does make filter() and map() faster on Python 3.6 compared to Python 2.7, but it's not directly related to this issue. IMHO using length hint would make list(filter) and list(map) even faster.
History
Date User Action Args
2016-04-22 12:12:40vstinnersetrecipients: + vstinner, alex, serhiy.storchaka
2016-04-22 12:12:40vstinnersetmessageid: <1461327160.24.0.621419084727.issue26828@psf.upfronthosting.co.za>
2016-04-22 12:12:40vstinnerlinkissue26828 messages
2016-04-22 12:12:40vstinnercreate