<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Sep 14, 2013, at 8:12 PM, Kyle Fisher <<a href="mailto:anthonyfk@gmail.com">anthonyfk@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span style="font-family: Arial; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; display: inline !important; float: none; ">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:</span></blockquote></div><br><div><br></div><div><div>It is surprising that you saw any performance gain at all.</div><div><br></div><div>Python already has a default Python freelist scheme </div><div>in the _PyObject_Malloc() function in Objects/obmalloc.c.</div><div><br></div><div>Another thought is that this isn't an inner-loop optimization.</div><div>The O(1) time for iterator creation is dominated by the O(n)</div><div>time to actually iterate over the dict keys, values, and items.</div><div><br></div><div>Raymond</div></div></body></html>