[Development] qt_add/removeObject hooks

Kevin Funk kfunk at kde.org
Thu Apr 17 18:11:03 CEST 2014


On Wednesday 16 April 2014 12:55:38 Matthew Woehlke wrote:
> On 2014-04-16 03:18, Volker Krause wrote:
> > On Tuesday 15 April 2014 08:02:56 Thiago Macieira wrote:
> >> In other words: use QBasicAtomicPointer.
> > 
> > As mentioned on https://codereview.qt-project.org/#change,83272 Kevin Funk
> > measured the difference between the current approach and using atomics
> > using Olivier's initial benchmark, it's about 4-5x slower for checking if
> > there's a callback set.

@Volker: The 4-5x slower version was the one trying to support the multiple-
callback-scenario (implemented inefficiently, apparently).

> How are you doing that check?
> 
> I believe the 'correct' way is 'if (callback)', which calls an inline
> operator that accesses the internal pointer directly, i.e.
> 'callback->operator T*' -> 'callback->_q_value' (which should further be
> the first member, and thus require no additional instructions to access
> versus a raw pointer type).
> 
> The only reason this should perform significantly different is if you're
> comparing it to a non-volatile raw pointer... and I'd be very, very
> suspicious of using a non-volatile raw pointer that may be written in
> another thread.

Now, using the straight-forward approach of just defining a 
QAtomicPointer<void(*)()> callback; and testing whether this one is set via 
'if (callback)', I get much better results using Olivier's testbench.

I get a ~1.5x slowdown with atomic pointers (test4) compared to the version 
using raw pointers (test2) on my machine.

New benchmark attached, so everyone can test on his/her own.

If the results can be confirmed, I wonder whether we should actually 
reconsider using QInternal for the hooking API...

Greets

PS: Sorry for the confusion with the initial benchmark results (I'm not sure 
what I've done there...)

-- 
Kevin Funk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: noop.cc
Type: text/x-c++src
Size: 91 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140417/1291b3df/attachment.cc>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ben.cc
Type: text/x-c++src
Size: 1688 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20140417/1291b3df/attachment-0001.cc>


More information about the Development mailing list