<div dir="ltr"><div><div><div>We tend to do a lot of iterating over dictionaries in our
product in some performance critical areas. It occurred to me that
allocating a new iterator object every single time seems a little
wasteful, especially considering that there's probably only a handful of
them alive at any time. Doing a quick test with dictiterobject and 3
free lists (one for Keys, Values and Items) showed about a 4% speedup in
this (best) case:<br>
<br>python -m timeit -s "a = {'k%d' % i: i for i in xrange($2)}" "[_ for _ in a.iteritems()]"<br><br></div>However,
this seems like almost too simple of an idea. Has this been tried
before? Would it be too little gain? Given that the extra memory used
is negligible (3 of each iterator?), how much of a performance gain
would be needed to justify it?<br>
<br></div>Thanks,<br></div>-Kyle</div>