From: Kevin W. <kev...@gm...> - 2007-12-11 04:23:43
|
> To be really faster, the variable has to be a function local - not a > module global as you propose. > > def Set(_swig_function_=_core_.Size_Set, *args, **kwargs): > return _swig_function_(*args, **kwargs) > > This way the attribute lookup is done when importing the module, and > no lookup occurs at runtime. I wasn't aware of this distinction, but it makes sense... > > As a disclaimer, I did take a peek into Python.cxx and saw lots and lots of > > messy c++ string manipulation, and ran scared :( > > Some years ago, I hacked swig to completely avoid the generation of > shadow classes: all the classes were defined in the *_wrap.cxx files, > and the .py was reduced to the minimum (that is, only %pythonextend > code). It even worked for wx... at the time. It was before the > introduction of the PySwigObject_Type, and would require some work to > resurrect. > > The result was interesting: "import wx" was three times faster, and > used 3Mb less memory. But I did not benchmark it really. I think the footprint of a barebones wxPython app is something like 25-30mb, which on the surface at least seems like a really absurd amount of bloat. I guess I don't understand the purpose of the "shadow classes." For example, in wxPython, for classes with callbacks, like a virtual list box, there is an "OnDrawItem" method that gets called with a rectangle for drawing the contents of a cell. Looking through the wxPython source I see that there is special case code for binding OnDrawItem so that it can be overridden by a Python method. Robin Dunn, the creator of wxPython, has told me that this kind of code predates directors--the new and preferred cross-language polymorphism magic. But directors are an "opt-in" feature, and shadow classes (and pass-through methods) for /every/ single method of every single class (of which there are a whole bunch in a library like wxWidgets) are not. So shadow classes are not providing this feature. What exactly are the technical reasons for them? And Amaury: if you still have code from this SWIG hacking kicking around somewhere public, please let me know :-). I'd be curious to see on what scale this kind of restructuring would entail. |