Remove inefficiencies created by introducing specific C++11 #503
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As SBE generates C++ code, it's doing more than it needs to do and in some cases, actually hurting performance.
First, SBE is generating a move constructor and move assignment operator for the generated class. However, the implementation of these methods are the exact same as their copy counter parts (see note below). Since T&& will be promoted to const T&, the copying methods are sufficient.
Next, the C++03 version of the class member template function forEach takes a single template parameter which is meant to be a functor. The signature has changed in C++11 version to take in a std::function. This is where the inefficiency is introduced. The implementation of std::function uses type-erasure to achieve its functionality. However, that means it's performing an allocation on the heap, copy the data of the functor, and invokes the functor indirectly which loses the ability to inline the method call. By leaving it as a template parameter, the compiler has the opportunity to inline the invocation altogether and allows the compiler to inline the invocation.
NOTE: We can take this a step further and declare that the copy constructor and copy assignment operator methods are not necessary since it's the exact same implementation that the compiler would generate for us anyway.