[Python-ideas] Keep free list of popular iterator objects
M.-A. Lemburg
mal at egenix.com
Sun Sep 15 13:52:39 CEST 2013
On 15.09.2013 13:30, Antoine Pitrou wrote:
> On Sun, 15 Sep 2013 12:56:15 +0200
> "M.-A. Lemburg" <mal at egenix.com> wrote:
>> On 15.09.2013 08:26, Kyle Fisher wrote:
>>> I've realized that my original example is far too complex, so I've
>>> simplified it:
>>>
>>> Status quo:
>>> ./python -m timeit -r 100 -s "a=[1]" "iter(a)"
>>> 10000000 loops, best of 100: 0.0662 usec per loop
>>>
>>> With patch:
>>> ./python -m timeit -r 100 -s "a=[1]" "iter(a)"
>>> 10000000 loops, best of 100: 0.0557 usec per loop
>>> List iter allocations: 6
>>> List iter reuse through freelist: 1011111554
>>> 100.00% reuse rate
>>>
>>> Which seems to show a 15% speedup. I'd be curious what others get.
>>
>> I'd suggest to open a ticket for this and then continue
>> the discussion there.
>>
>> Given how often iterators are used nowadays in Python, a separate
>> free list may actually make sense (for the same reasons it makes
>> sense to have them around for lists, tuples, etc.).
>
> I'm -1 on adding freelists everywhere.
Not everywhere :-) Just for objects that are often created
and freed again.
> A best-case 15% improvement on a
> trivial microbenchmark probably means a 0% improvement on real-world
> workloads. Furthermore, using specialized freelists will increase
> memory fragmentation and prevent the main allocator from returning
> memory to the system.
Keeping e.g. a hundred such objects in a free list shouldn't
really affect the memory load of the Python interpreter.
A 15% improvement isn't a lot, but such small improvements
add up if they are consistent and the net result is an overall
performance improvement.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source (#1, Sep 15 2013)
>>> Python Projects, Consulting and Support ... http://www.egenix.com/
>>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
2013-09-11: Released eGenix PyRun 1.3.0 ... http://egenix.com/go49
2013-09-04: Released eGenix pyOpenSSL 0.13.2 ... http://egenix.com/go48
2013-09-20: PyCon UK 2013, Coventry, UK ... 5 days to go
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-ideas
mailing list