Discussion:
[eigen] MSVC bad inlining behavior
Basil Fierz
2018-03-25 14:13:06 UTC
Permalink
Hi Eigen developers,

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:
https://godbolt.org/g/Q8Bvxv

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:
https://bitbucket.org/eigen/eigen/pull-requests/345

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.

Best regards,

Basil
Patrik Huber
2018-03-25 23:34:44 UTC
Permalink
Hi Basil,

I'm just an Eigen user, but have you reported this to
https://developercommunity.visualstudio.com? You can report it directly
from within VS 2017.
Particularly if you have a self-contained, minimal example, like you do, I
bet they would be very interested in it, and nowadays they are also very
responsive and often even push fixes to release within one or two minor
versions (a few months). Let me know the link if you do post it, I'd be
curious to see where this goes.

Best regards,

Patrik
Post by Basil Fierz
Hi Eigen developers,
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
https://godbolt.org/g/Q8Bvxv
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
https://bitbucket.org/eigen/eigen/pull-requests/345
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.
Best regards,
Basil
Basil Fierz
2018-03-26 08:15:43 UTC
Permalink
Hi Patrik,

Thank you for the suggestion. I've reported it to Microsoft:
https://developercommunity.visualstudio.com/content/problem/222740/c-weak-inlining.html
Naturally, this does not solve issue for my current work environment (and people who might still need to build for older Microsoft compilers).

Best regards,

Basil

________________________________
From: Patrik Huber <***@gmail.com>
Sent: Monday, March 26, 2018 01:34
To: ***@lists.tuxfamily.org
Subject: Re: [eigen] MSVC bad inlining behavior

Hi Basil,

I'm just an Eigen user, but have you reported this to https://developercommunity.visualstudio.com<https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdevelopercommunity.visualstudio.com&data=02%7C01%7C%7C770cb0c9a3e2479746c708d592a9184b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636576177311232890&sdata=ldrj89NVyX2NHwAI3icAVkJx3Z2hhRiRHQNFufBc24I%3D&reserved=0>? You can report it directly from within VS 2017.
Particularly if you have a self-contained, minimal example, like you do, I bet they would be very interested in it, and nowadays they are also very responsive and often even push fixes to release within one or two minor versions (a few months). Let me know the link if you do post it, I'd be curious to see where this goes.

Best regards,

Patrik

On 25 March 2018 at 15:13, Basil Fierz <***@hotmail.com<mailto:***@hotmail.com>> wrote:

Hi Eigen developers,



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:

https://godbolt.org/g/Q8Bvxv<https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fg%2FQ8Bvxv&data=02%7C01%7C%7C770cb0c9a3e2479746c708d592a9184b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636576177311232890&sdata=EmUyxVJrQ4Z668LBodU%2FWPKkCGEOCRImcityMPHaAmU%3D&reserved=0>



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:

https://bitbucket.org/eigen/eigen/pull-requests/345<https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbitbucket.org%2Feigen%2Feigen%2Fpull-requests%2F345&data=02%7C01%7C%7C770cb0c9a3e2479746c708d592a9184b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636576177311232890&sdata=GAGOB%2BEONebIoNfncdZWxK20TYRZRfOyJg1txkanOMI%3D&reserved=0>



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.



Best regards,



Basil
Julian Kent
2018-03-26 17:41:48 UTC
Permalink
Hello Basil

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

Best regards
Julian
Post by Basil Fierz
Hi Patrik,
https://developercommunity.visualstudio.com/content/problem/222740/c-weak-
inlining.html
Naturally, this does not solve issue for my current work environment (and
people who might still need to build for older Microsoft compilers).
Best regards,
Basil
------------------------------
*Sent:* Monday, March 26, 2018 01:34
*Subject:* Re: [eigen] MSVC bad inlining behavior
Hi Basil,
I'm just an Eigen user, but have you reported this to
https://developercommunity.visualstudio.com
<https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdevelopercommunity.visualstudio.com&data=02%7C01%7C%7C770cb0c9a3e2479746c708d592a9184b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636576177311232890&sdata=ldrj89NVyX2NHwAI3icAVkJx3Z2hhRiRHQNFufBc24I%3D&reserved=0>?
You can report it directly from within VS 2017.
Particularly if you have a self-contained, minimal example, like you do, I
bet they would be very interested in it, and nowadays they are also very
responsive and often even push fixes to release within one or two minor
versions (a few months). Let me know the link if you do post it, I'd be
curious to see where this goes.
Best regards,
Patrik
Hi Eigen developers,
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
https://godbolt.org/g/Q8Bvxv
<https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fg%2FQ8Bvxv&data=02%7C01%7C%7C770cb0c9a3e2479746c708d592a9184b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636576177311232890&sdata=EmUyxVJrQ4Z668LBodU%2FWPKkCGEOCRImcityMPHaAmU%3D&reserved=0>
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
https://bitbucket.org/eigen/eigen/pull-requests/345
<https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbitbucket.org%2Feigen%2Feigen%2Fpull-requests%2F345&data=02%7C01%7C%7C770cb0c9a3e2479746c708d592a9184b%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636576177311232890&sdata=GAGOB%2BEONebIoNfncdZWxK20TYRZRfOyJg1txkanOMI%3D&reserved=0>
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.
Best regards,
Basil
Gael Guennebaud
2018-03-27 07:48:25 UTC
Permalink
Hi,

Sorry for overlooking your PR, I don't have much time to devote to Eigen
these days.

Thank you for investigating these inlining issues. Your changes look
reasonable and I've merged the PR and ported it to the main branch.

best,
gael
Post by Basil Fierz
Hi Eigen developers,
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
https://godbolt.org/g/Q8Bvxv
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
https://bitbucket.org/eigen/eigen/pull-requests/345
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.
Best regards,
Basil
Basil Fierz
2018-03-27 18:19:44 UTC
Permalink
Hi Gael,

Thanks for merging the PR. As we are using Eigen heavily in performance critical areas, I am going to monitor these kinds compilation failures and maybe issue some further pull-requests.

Best regards,

Basil

From: Gael Guennebaud <***@gmail.com>
Sent: 27 March 2018 09:48
To: eigen <***@lists.tuxfamily.org>
Subject: Re: [eigen] MSVC bad inlining behavior

Hi,

Sorry for overlooking your PR, I don't have much time to devote to Eigen these days.

Thank you for investigating these inlining issues. Your changes look reasonable and I've merged the PR and ported it to the main branch.

best,
gael

On Sun, Mar 25, 2018 at 4:13 PM, Basil Fierz <***@hotmail.com<mailto:***@hotmail.com>> wrote:
Hi Eigen developers,

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:
https://godbolt.org/g/Q8Bvxv<https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fg%2FQ8Bvxv&data=02%7C01%7C%7C4a876e8c592949dcd22a08d593b75452%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636577337952253906&sdata=nbdtuC5q28cdrODNJ33a4PQovIq8YwDwU2Crxt2X2vU%3D&reserved=0>

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:
https://bitbucket.org/eigen/eigen/pull-requests/345<https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbitbucket.org%2Feigen%2Feigen%2Fpull-requests%2F345&data=02%7C01%7C%7C4a876e8c592949dcd22a08d593b75452%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636577337952253906&sdata=oIKuxoWfmF6fpSs%2Bbgga0szg6IM2FsQ89Z4pHbh4bxw%3D&reserved=0>

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.

Best regards,

Basil
Gael Guennebaud
2018-03-28 07:23:29 UTC
Permalink
I'm glad someone is looking at such matters.

gael
Post by Basil Fierz
Hi Gael,
Thanks for merging the PR. As we are using Eigen heavily in performance
critical areas, I am going to monitor these kinds compilation failures and
maybe issue some further pull-requests.
Best regards,
Basil
*Sent:* 27 March 2018 09:48
*Subject:* Re: [eigen] MSVC bad inlining behavior
Hi,
Sorry for overlooking your PR, I don't have much time to devote to Eigen these days.
Thank you for investigating these inlining issues. Your changes look
reasonable and I've merged the PR and ported it to the main branch.
best,
gael
Hi Eigen developers,
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
https://godbolt.org/g/Q8Bvxv
<https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgodbolt.org%2Fg%2FQ8Bvxv&data=02%7C01%7C%7C4a876e8c592949dcd22a08d593b75452%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636577337952253906&sdata=nbdtuC5q28cdrODNJ33a4PQovIq8YwDwU2Crxt2X2vU%3D&reserved=0>
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
https://bitbucket.org/eigen/eigen/pull-requests/345
<https://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbitbucket.org%2Feigen%2Feigen%2Fpull-requests%2F345&data=02%7C01%7C%7C4a876e8c592949dcd22a08d593b75452%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636577337952253906&sdata=oIKuxoWfmF6fpSs%2Bbgga0szg6IM2FsQ89Z4pHbh4bxw%3D&reserved=0>
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.
Best regards,
Basil
Loading...