[Development] qt_add/removeObject hooks

Olivier Goffart olivier at woboq.com
Tue Apr 8 23:00:18 CEST 2014


On Tuesday 08 April 2014 07:42:46 Thiago Macieira wrote:
> Em ter 08 abr 2014, às 15:49:16, Volker Krause escreveu:
> > API-wise we are quite flexible (can't get any more dirty than what we do
> > now ;) ), I was mainly asking due to this being on a performance-relevant
> > path. The QInternal callback system is obviously more flexible (and thus
> > would be my preferred choice), but also slightly more expensive at
> > runtime. The signal spy approach would be slightly more light-weight, at
> > the cost of thread-safety. So, if from the performance point of view
> > there are no objections to the QInternal callback approach, I'll make
> > sure the Squish team is happy with that too, and propose a patch
> > accordingly.
> 
> Performance-wise, I'd prefer empty functions that get overridden at runtime.
> That's the smallest overhead for when they are not present.

According to a quick benchmark (attached), it is clearly more efficient to 
have:
  if (callback) callback();
where callback is a function pointer than always calling callback even if it 
is an empty function.

For this reason, I'd recommend an approach based on function pointer callbacks 
such as QInternal::registerCallback
(but that one is using a QGlobalStatic, so there is room for improvement)

-- 
Olivier 

Woboq - Qt services and support - http://woboq.com - http://code.woboq.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ben.cc
Type: text/x-c++src
Size: 1349 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140408/d74c7eda/attachment.cc>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: noop.cc
Type: text/x-c++src
Size: 67 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140408/d74c7eda/attachment-0001.cc>


More information about the Development mailing list