[PyKDE] Speed of derived objects

Michael Lauer mickey at tm.informatik.uni-frankfurt.de
Mon Nov 25 14:10:00 GMT 2002


Am Son, 2002-11-24 um 23.35 schrieb Vincent Wagelaar:
> I am currently working with a QListView and QListViewItem. If I don't derive 
> from these objects speed is great, but derived these objects become very 
> slow. 

First of all - 
you are experiencing an inherent fact in the nature of Python bindings
which support deriving and virtual methods. If you don't subclass,
there's nearly no Python code involved - if you do subclass, your
(really really slow - compared to the speed of executing code in C/C++
extension modules) Python code is called. There's nothing you can do
about this fact.

>What is the usual approach for speeding this up?

You have to be very careful about _what_ methods you overload. For
instance, overloading event() is a very bad idea, because event() is
called very often - hence slow Python code gets executed very often.
Also, try implementing behaviour using C++-SIGNALS wherever it is
possible. You might want to check if removing your additional debugging
code (print statements are known to slow down very much) makes a
difference, too.

If this all don't work for you, then I'm afraid you have to implement
your derived class in C++ and use sip to bind this and use it from
Python.

Yours,

Mickey.
-- 
:M:
--------------------------------------------------------------------------
Dipl.-Inf. Michael 'Mickey' Lauer  
mickey at tm.informatik.uni-frankfurt.de 
  Raum 10b - ++49 69 798 28358       Fachbereich Informatik und Biologie
--------------------------------------------------------------------------





More information about the PyQt mailing list