PDA

View Full Version : Qt g++ optimization



Krish_ng
1st August 2007, 13:34
I hav developed an application for which performance is a constraint .Is there any method to optimize the g++ of Qt..Any ideas....I hav tried modifying makefile g++ FLAGS with -O3 -ffast-math -funroll-loops to optimize the code..But the performance is the same.

marcel
1st August 2007, 13:44
If you ut it this way, there isn't much you can improve with compiler options. This is more like a "cosmetic" option.
Usually, from my experience, the layouts are the slowest in Qt. I mean complex nested layouts.

Have you profiled your application to see which parts take the longest time to execute?

Maybe there are some parts in your code that can be optimized to run faster.
You should provide more details, such as what is not optimal in your opinion.

Regards

fullmetalcoder
1st August 2007, 13:50
I hav developed an application for which performance is a constraint .
Then optimize your code... compiler tries their best to optimize the assembly output but they cannot refactor your code... you can spot where CPU time is spent through various tools (for instance Valgrind) and then optimize the faulty code.

p.s. : v=looks like a double thread to me... you should avoid this for it won't make answers come any faster...

Krish_ng
1st August 2007, 14:12
My application has a scroll which takes time ...i hav used getTimeofday() to get the time of
execution for the scroll.The scroll is done in eventfilter.When i used -ffast-math and -funroll-loops thers was a little diff in time..So if i can disable some of g++ flags,it may perform better.i guess....Any idea wat are the default flags enabled for 02...

marcel
1st August 2007, 14:19
Could you post some code?
I am sure this can be solved by optimizing the code rather than testing gcc flags.

Regards

fullmetalcoder
1st August 2007, 14:29
My application has a scroll which takes time ...i hav used getTimeofday() to get the time of
execution for the scroll.The scroll is done in eventfilter.When i used -ffast-math and -funroll-loops thers was a little diff in time..So if i can disable some of g++ flags,it may perform better.i guess....Any idea wat are the default flags enabled for 02...
If you want to see by yourself how much time is spent doing a precise task use QTime :

QTime t;
t.start();

// do some things here

qDebug("things tooks %i ms", t.elapsed());

And, as I said already, investigate your code. If your algorithms are a mess, no matter how much they are optimized by the compiler, they will still waste a lot of CPU time... Unless you can't afford showing your code for any reasons you'd better post it here so that someone might suggest improvements...

Krish_ng
1st August 2007, 14:41
bool QMyView::eventFilter(QObject *target, QEvent *event)
{

if (event->type() == QEvent::KeyPress)
{
//typecast QEvent to QKeyEvent
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
//following are checking for target widget where event happens
//checks whether target is listwidget
if(target==this)
{
//checks whether pressed key is 1
if (keyEvent->key() == Qt::Key_1 )
{

m_pMyViewButtonBar->showDialog(this);

here i am using an instance of a splitter to show a dialog
}
else
{
//checks whether pressed key is down
if (keyEvent->key() == Qt::Key_Down )
{
//checks m_count is for number of items upto down scroll to be done
if(m_iCount!=-1 && m_iCount<23)
{
/ /each time 10 items are get scrolled down
m_iCount=m_iCount+10; updateAllMyMainWindowViews(m_iCount,m_iCount+15);
//place where time is spent for execution
}
}
//checks whether pressed key is down
else if(keyEvent->key() == Qt::Key_Up)
{
//checks m_count is for total number of items upto up scroll to be done
if(m_iCount>0)
{
//each time 10 items are get scrolled up
m_iCount=m_iCount-10;
updateAllMyMainWindowViews(m_iCount,m_iCount+15);
}
}
//checks whether pressed key is alt
else if(keyEvent->key() == Qt::Key_Alt)
{
//checks itemcount is not eqalto -1
if(m_iCount!=-1)
{

updateAllMyMainWindowViews(m_iCount,m_iCount+15);
}
}
}
}

}



void QMyView::updateAllMyWindowViews(INT32 start,INT32 end)
{

//From event filter i am trying to updte tha list items
//in event i am trying to update the listwidget items..The listwidget is added to a splitter
m_pSplitterView->updateFirstView(start, end);
m_pSplitterView->updateSecondView(start, end);
m_pSplitterView->updatethirdView(start, end);
m_pSplitterView->updateFourthView(m_iScrollInitialValue, m_iScrollMaxValue);

}



I hav an application with a splitter that has 4 listwidgets.I am trying to update 14 items on each scroll,using ScrollToitem in the update methods...How can reduce this scroll time

marcel
1st August 2007, 15:00
First of all: eventFilter is reentrant. Meaning that you modify a widget inside it, then it will reenter.

Second of all: you install a widget as an eventfilter for itself( target == this ). This is not OK. Use event() instead if you want to catch key presses for a widget.

Try not to show dialogs from inside event handlers. Also do not modify widgets in event handlers. This could lead to recursion. Therefore your program's lagging.

Regards

Krish_ng
2nd August 2007, 09:20
I hav changed my code and hav used keyPressEvent instead of eventFilter...I need to show
a dialog when Key_1 is pressed. Then should i give dilaog->show() in event or some other place...I even want show a scroll of 10 items when up and dwn keys..Then i should
update the list items in event ????Any ideas