Easy to do optimization

Cyrille Berger cberger at cberger.net
Fri Oct 20 11:41:40 CEST 2006


Hi,
As soon as you see slow code, try to have a look at the code to see if we 
aren't creating a lot of unnecesserary objects, 90% of the time slow code is 
caused by this (the remain 10% are often caused by a lot of access to the 
tilesmanager, like with random accessor)

For instance:
* Avoid:
for(whatever)
{
	QColor c;
	...
}
Do:
QColor c;
for(whatever)
{

}
It might seems insignificant, but really it's not, on a loop of a milion of 
iterations, this is expensive as hell.

An other example:
* avoid
for(y = 0 to height)
{
	KisHLineIterator it = dev->createHLineIterator(0, y, width);
	for(whatever)
	{
		...
	}
}
Do:
KisHLineIterator it = dev->createHLineIterator(0, y, width);
for(y = 0 to height)
{
	for(whatever)
	{
		...
	}
	it.nextRow(); // or nextCol() if you are using a VLine iterator
}

Once we have done the two above optimization, we will allready have a much 
more faster krita :)
-- 
--- Cyrille Berger ---


More information about the kimageshop mailing list