[Development] qt_add/removeObject hooks

Milian Wolff milian.wolff at kdab.com
Tue Apr 22 21:02:24 CEST 2014


On Thursday 17 April 2014 18:11:03 Kevin Funk wrote:
> 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...

For me, I don't see any difference at all:

$ clang++ -O3 -std=c++11 -I/usr/include/qt/ -lQt5Core -fPIE test.cpp noop.cpp 
-o bench && ./bench
test1 1438 
test2 482 
test3 1435 
test4 479 
test5 1434 
test4 479 
test3 1435 
test2 479 
test1 1435 

Note that I extended the benchmark by also checking the case of a set callback 
in the QAtomicPointer. I also cleaned up the code a bit, see here: 
http://paste.kde.org/p5ixo5oyr

BTW: Did you really compile this with Qt5? The operator T*() is gone from 
QAtomicPointer, no? https://qt-project.org/doc/qt-5/qatomicpointer-members.html

Cheers
-- 
Milian Wolff | milian.wolff at kdab.com | Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel. Germany +49-30-521325470, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions



More information about the Development mailing list