On Wed, Jan 5, 2011 at 5:27 AM, Maciej Fijalkowski email@example.com wrote:
How about not changing semantics and still making this optimization possible?
PyPy already has CALL_LIKELY_BUILTIN which checks whether builtins has been altered (by keeping a flag on the module dictionary) and if not, loads a specific builtin on top of value stack.
I can only repeat what I said before. That's what everybody proposes, and if you have the infrastructure, it's a fine solution.
But to me, those semantics aren't sacred, and I want to at least explore an alternative.
Putting a hook on two dicts (the module globals and builtins.__dict__) is a lot of work in CPython, and has the risk of slowing everything down (just a tad, but still -- AFAIK dicts currently are not hookable). Checking whether there's a global named 'len' is much simpler in the current CPython compiler.