Re: [Pyobjc-dev] Another naive question
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2002-11-17 13:08:51
|
On Sunday, Nov 17, 2002, at 00:50 Europe/Amsterdam, Just van Rossum wrote: > bb...@ma... wrote: > >> [ ... ] Unfortunately, from AppKit import NSApplication causes the >> AppKit module to effectively visit every class in the runtime as a >> part of initialization -- and this is quite expensive. > > Ah, so that's the bottleneck. I'd be intersted in figuring out whether > this can > be done lazily, but I'll need to familiarize myself with the source > first... The interesting part for this is the function load_bundle in Lib/Foundation/__init__.py. This loads a bundle and then loops through all classes in the runtime to find those that are defined in the just loaded bundle. The expensive part is creating proxy classes for all classes in the objective-C runtime. If you do 'objc.lookup_class' PyObjC only creates proxies for the class itself and any superclasses. I've thought about initializing classes lazily, but need to look into the feasability of this: You must fully initialize the proxy class before creating the first instance of the class, otherwise method lookup might not work. Now that I write this down I start to think that this is possible to do this: We already have mechanism to detect if the method table of an Objective-C class has changed and might as wel use that for lazy initialization. I'll look into this. Ronald |