Eigen inlining with MSVC

It looks like Eigen’s having a hard time inlining code with MSVC. This was from Basil Fierz on the Eigen list 25 March 2018. No response, so no idea if they will start inlining more agressively.

I’m using Eigen (personally and professionally) for quite a few years, mainly to solve many small fixed-size problems. While the template expression engine is a wonderful tool to optimize the generated code, it only works reasonable well using clang/gcc. Using MSVC we’re constantly running into the issue that a lot of code is not properly inlined, which in turn hurts performance massively.
The issue can usually be resolved by patching Eigen and replacing some ‘inline’ with ‘EIGEN_STRONG_INLINE’. I’ve collected some very simple examples which demonstrate the problem:

The example is compiled using MSVC 2017 and Clang 4. In each of them the former does not properly inline the calls, while Clang does.
There is a lot of other cases where this happens. The most frustrating ones are some where calls to ‘derived()’ are found in the code as they should essentially be no-ops. While I don’t see Eigen as a culprit, I would like to propose adapting Eigen to accommodate for the bad inlining engine of MSVC. Some time ago, I’ve created a PR which at least fixes the most annoying inlining problems for us:

I am open to different solutions for this problem. If adding ‘EIGEN_STRONG_INLINE’ to the core structures of Eigen, I will give it another more complete try.

1 Like

Never mind. Julian Kent followed up on their list:

Just to note, if you change from floats to doubles you get full inlining.

That’s the only case we care about so far.