Silly function call lookup stuff?
Lucas Lemmens
llemmens at gmx.net
Tue Sep 27 18:38:23 EDT 2005
On Tue, 27 Sep 2005 13:56:53 -0700, Michael Spencer wrote:
> Lucas Lemmens wrote:
>> Dear pythonians,
>>
>> I've been reading/thinking about the famous function call speedup trick
>> where you use a function in the local context to represent a "remoter"
>> function to speed up the 'function lookup'.
>>
>> "This is especially usefull in a loop where you call the function a
>> zillion time" they say.
>>
>> I think this is very odd behavior.
>>
>> Why isn't the result of the first function-lookup cached so that
>> following function calls don't need to do the function-lookup at all?
>>
> I guess because the function name may be re-bound between loop iterations.
> Are there good applications of this? I don't know.
Yuk I'd hate that. I think it would be extremely rare.
Would the myLocalFunc = hisRemoteFunc optimization break in such a case?
If not then why not auto-add a local hisRemoteFunc that points to the
remote hisRemoteFunc to the local context when hisRemoteFunc
is executed for the first time.
>
>> And if the context changes (an import-statement say) reset the cached
>> 'function-lookups'.
>
> In general an object doesn't know what names are bound to it and there are
> many ways besides an import statement of binding/re-binding, so "if the
> context changes" is easier said than done.
>
My guess (but I'm not a python programmer) is that context changes would
be the odd case.
So optimizing for not having them ...
>
>> This way any function would only need to be looked up once.
>>
>> L.
>>
> Would you apply this optimization to all lookups in outer scopes, or just
> callables? Why? ;-)
Hmmm callables have probably the highest chance of being recalled.
>
> Michael
More information about the Python-list
mailing list