[PyKDE] Speed of derived objects

Vincent Wagelaar vincent at ricardis.tudelft.nl
Mon Nov 25 21:55:01 GMT 2002


On Monday 25 November 2002 14:06, Michael Lauer wrote:
> 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.

I think I'll will have to go for the SIP-method because I'm overloading the 
paint method in QListViewItem (called a lot).

The code looks like:

class MyListViewItem(QListViewItem):
	def paint():
		# My overridden paint stuff
	def key():
		# My overloaded sorting stuff...

Overloading QListView shouldn't give a performance degradation because it's 
only called once. Nothing compared to how many times MyListViewItem is 
called.

> 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.

I'm affraid so too, but shouldn't give that many troubles. I've also tried 
Psyco but that didn't give a speed boost either.

Thanks for the reply

Vincent





More information about the PyQt mailing list