[Transaction] Replace template for functor with std::function
ClosedPublic

Authored by bruns on Jun 9 2019, 10:54 PM.

Details

Summary

The callback parameter has a specific type, it accepts a document ID and
returns bool, while the template is overly broad.

Diff Detail

Repository
R293 Baloo
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
bruns created this revision.Jun 9 2019, 10:54 PM
Restricted Application added projects: Frameworks, Baloo. · View Herald TranscriptJun 9 2019, 10:54 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
bruns requested review of this revision.Jun 9 2019, 10:54 PM

I thought about it myself. I googled it a bit (i.e. here) and saw that there might be some quite unwanted runtime overhead because of using std::function. It might be negligible (since we're doing some costly DB operations inside anyways), but I'd prefer if we did some profiling to make sure it's OK.

bruns added a comment.Jun 10 2019, 1:29 PM

I thought about it myself. I googled it a bit (i.e. here) and saw that there might be some quite unwanted runtime overhead because of using std::function. It might be negligible (since we're doing some costly DB operations inside anyways), but I'd prefer if we did some profiling to make sure it's OK.

There are two causes mentioned why the template may be faster:

  1. the compiler may be able to inline or even remove a trivial template
  2. the std::function may need to heap-allocate the space for the bound values (either for captured values of a lambda, or when using std::bind)

Neither applies here. (1.) is obviously not the case.

(2.) does not apply, as the lambda is bound outside the loop, nothing has to be copied or allocated in the loop.

ngraham accepted this revision.Jun 10 2019, 1:57 PM

Yep, seems sensible.

This revision is now accepted and ready to land.Jun 10 2019, 1:57 PM
This revision was automatically updated to reflect the committed changes.