I'm working on a project that uses a QThread to process communication over a TCP connection. In trying to improve performance I've tracked down an odd slow-down when we use QMethod::invoke to force a method to be called on the correct thread.
This is an embedded project running on a Freescale i.MX53. On this board, I've measured the time to make this call and it is on average around 400000 ns. I've measured this on our i.MX6 board as well (with only one core enabled) and it takes only 60000 ns. This doesn't look right to me. I would expect the difference to be at most 2x, not 6x. Is there something I'm missing here in my expectations or is there something fundamentally wrong causing this slow-down? I'm including my test code which I've run on both targets. In the sample code I'm using Qt::BlockingQueuedConnection when calling invoke - normally we don't do that but for the test it makes it much simpler to see the effect of the slow-down. - Robert Daniels #include <QCoreApplication> #include <QThread> #include <QMetaMethod> #include <QDebug> #include <QTimer> #include <QElapsedTimer> class WorkerThread : public QThread { Q_OBJECT public: WorkerThread() { moveToThread(this); method = metaObject()->method(metaObject()->indexOfMethod("myMethod(int)")); start(); sum = 0; qDebug() << "Started Worker Thread."; } Q_INVOKABLE void myMethod(int test) { if (currentThread() != this) { method.invoke(this, Qt::BlockingQueuedConnection, Q_ARG(int, test)); } else { sum += test; } } int getSum() { return sum; } private: QMetaMethod method; int sum; }; class Test : public QObject { Q_OBJECT public: Test() { QTimer *timer = new QTimer(this); timer->setInterval(10); connect(timer, SIGNAL(timeout()), SLOT(onTimer())); timer->start(); } private slots: void onTimer() { qDebug() << "Begin test."; QElapsedTimer timer; qint64 total = 0; const int cnt = 100000; for (int i = 0; i < cnt; i++) { timer.start(); worker.myMethod(i); total += timer.nsecsElapsed(); } qDebug() << "Average ms:" << (total / cnt) << "sum =" << worker.getSum(); worker.exit(); QCoreApplication::exit(); } private: WorkerThread worker; }; int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Test test; return a.exec(); } #include "main.moc" ________________________________ Ce message, ainsi que tous les fichiers joints à ce message, peuvent contenir des informations sensibles et/ ou confidentielles ne devant pas être divulguées. Si vous n'êtes pas le destinataire de ce message (ou que vous recevez ce message par erreur), nous vous remercions de le notifier immédiatement à son expéditeur, et de détruire ce message. Toute copie, divulgation, modification, utilisation ou diffusion, non autorisée, directe ou indirecte, de tout ou partie de ce message, est strictement interdite. Se désabonner: Si vous souhaitez être retiré de notre liste de diffusion, s'il vous plaît envoyer vos coordonnées à casl.unsubscr...@legrand.ca<mailto:casl.unsubscr...@legrand.ca> et indiquer quels sont les messages que vous ne souhaitez plus recevoir. This e-mail, and any document attached hereby, may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized, direct or indirect, copying, disclosure, distribution or other use of the material or parts thereof is strictly forbidden. Unsubscribe: If you would like to be removed from our mailing list, please send your contact information to casl.unsubscr...@legrand.ca<mailto:casl.unsubscr...@legrand.ca> and indicate what messages you no longer wish to receive. _______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest