<br><br><div><span class="gmail_quote">On 12/19/06, <b class="gmail_sendername">Andrea Griffini</b> &lt;<a href="mailto:agriff@tin.it">agriff@tin.it</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I&#39;m experimenting with a patch for dictionary lookup caching, the<br>main idea being avoiding the lookup of a constant (co_names) in<br>a dictionary if the dictionary didn&#39;t change since last lookup.<br><br>Currently the cache is held in a structure that is parallel to
<br>co_names (the LOAD_GLOBAL opcode uses oparg to access<br>the cache slot) and this is wasteful if there are co_names entries<br>that are not used for global lookups.<br><br>Probably I could act at the code object creation time to
<br>sort names so that ones used by LOAD_GLOBAL are<br>at the beginning of co_names but this would require inspecting<br>and hacking the already generated opcode.<br>Another case that would IMO be worth optimizing is the<br>
LOAD_ATTR lookup when it&#39;s done after a LOAD_GLOBAL<br>(I suspect that in many cases the element being searched will<br>be a module so caching would be simple to implement; for<br>general objects things are way more complex and I see no
<br>simple solution for caching dictionary lookups).<br><br>My opinion is that it would be by far better to do this ordering<br>of co_names at compile time but I&#39;ve no idea where to look<br>for trying to make such a change.
<br><br>Can someone please point me in the right direction ?</blockquote><div><br>For guidance on how the compiler works, see PEP 339 (<a href="http://www.python.org/dev/peps/pep-0339">http://www.python.org/dev/peps/pep-0339
</a>).<br><br>-Brett<br></div><br></div><br>