[Python-ideas] Keep free list of popular iterator objects

Antoine Pitrou solipsis at pitrou.net
Sun Sep 15 13:30:23 CEST 2013


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 around for lists, tuples, etc.).

I'm -1 on adding freelists everywhere. 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.

Regards

Antoine.




More information about the Python-ideas mailing list