Early binding as an option

Thomas Jollans t at jollybox.de
Tue Aug 2 20:10:15 CEST 2011

On 02/08/11 19:42, Chris Angelico wrote:
> On Tue, Aug 2, 2011 at 6:18 PM, Thomas Jollans <t at jollybox.de> wrote:
>> I suppose it would be possible to introduce a kind of "constant
>> globals" namespace that a JIT compiler could then use to optimise, but
>> how much would this help?
> Surely it must help a lot; looking up names is string operations. If
> "len" could be replaced with "@10794928" where 10794928 is the actual
> address of the len object, then it'd be doing no work that isn't
> normally done, and would go straight to the object and call it.
> But I don't really know how to go about profiling this to be sure. Any ideas?

Well, you could run a direct comparison of one function where len is
global, and an identitical function where len is local (which does not
do a dict lookup, am I right?)

Of course the global dict lookup takes time, but I doubt that many
modules look up the same name often enough for it to actually be

I don't really know enough about either profiling or the CPython
interpreter, but I assume there's some function that's called to look up
globals; you could profile the Python interpreter (don't ask me with
which tool) and see how much time that function uses.


More information about the Python-list mailing list