Optimize: use QMetaObject::invokeMethod with functor
ClosedPublic

Authored by mwolff on Jan 11 2018, 3:11 PM.

Details

Summary

When using this method with a string argument, the method would need
to be queried every time via QMetaObject::indexOfMethod. Using a
functor one can get rid of this, saving a few cycles which can
add up when handling many inotify events.

Note that the benchmark timing does not really improve significantly.
Using a profiler like perf, we do see that less cycles are consumed
though. In my measurement, this reduces the cpu cyles by about 2%.

Diff Detail

Repository
R244 KCoreAddons
Lint
No Linters Available
Unit
No Unit Test Coverage
mwolff created this revision.Jan 11 2018, 3:11 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptJan 11 2018, 3:11 PM
Restricted Application added a subscriber: Frameworks. · View Herald Transcript
mwolff requested review of this revision.Jan 11 2018, 3:11 PM
apol accepted this revision.Jan 11 2018, 3:19 PM
This revision is now accepted and ready to land.Jan 11 2018, 3:19 PM
mwolff planned changes to this revision.Jan 11 2018, 3:44 PM

requires 5.10, so I can't commit this as-is...

mwolff updated this revision to Diff 25172.Jan 11 2018, 3:52 PM

make compile against older Qt

This revision is now accepted and ready to land.Jan 11 2018, 3:52 PM
apol added a comment.Jan 11 2018, 3:59 PM

Maybe it would be cleaner to do QTimer::singleShot(0, c.instance, lambda).

cleaner, yes. but also much slower. contrary to the other code-paths, the QTimer::singleShot taking a functor is not optimized (yet?) for timeout == 0...

apol added a comment.Jan 11 2018, 4:18 PM

cleaner, yes. but also much slower. contrary to the other code-paths, the QTimer::singleShot taking a functor is not optimized (yet?) for timeout == 0...

Oh well... ¯\_(ツ)_/¯

mpyne accepted this revision.Jan 12 2018, 12:23 AM
mpyne added a subscriber: mpyne.

LGTM

dfaure requested changes to this revision.Jan 12 2018, 9:12 AM
dfaure added inline comments.
src/lib/io/kdirwatch.cpp
1405

Does this compile? The compiler in my eyes says: missing trailing semicolon.

This revision now requires changes to proceed.Jan 12 2018, 9:12 AM
mwolff updated this revision to Diff 25366.Jan 15 2018, 8:40 AM

thanks dfaure ;-)

dfaure accepted this revision.Jan 15 2018, 8:43 AM
This revision is now accepted and ready to land.Jan 15 2018, 8:43 AM
This revision was automatically updated to reflect the committed changes.