This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 1765 - Regression with MSVC 19.16 and later in C++17 mode
Summary: Regression with MSVC 19.16 and later in C++17 mode
Status: RESOLVED WONTFIX
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - general (show other bugs)
Version: 3.3 (current stable)
Hardware: All Windows
: Normal Performance Problem
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 3.x
  Show dependency treegraph
 
Reported: 2019-10-31 10:57 UTC by Christoph Hertzberg
Modified: 2019-12-04 18:52 UTC (History)
4 users (show)



Attachments

Description Christoph Hertzberg 2019-10-31 10:57:24 UTC
Reported via mail:

> In some of our code using Eigen, we got a 50% increase in runtime 
> when updating from C++14 to C++17.
> We are using Eigen 3.3.7 and MSVC 19.23.
> 
> Below is a small example, which gives different assembly on Godbolt.org,
> when compiled with
>    *   MSVC 19.22 /std:c++14 /O2 /Ob2 /GS-
>    *   MSVC 19.22 /std:c++17 /O2 /Ob2 /GS-
> 
> It seems that with C++17, the constructor call is not optimized so the
> runtime is much larger. Do you know what is going on?
> 
> #include <Eigen/Core>
> int main()
> {
>   for (size_t i = 0; i < 0.3e9; ++i)
>   {
>     Eigen::Matrix2cd R;
>   }
>   return 0;
> }

I confirm this, even with /DNDEBUG, but it seems to be a regression from MSVC 19.15 to 19.16 (the constructor of std::complex does not get optimized away):

https://godbolt.org/z/7WDacA

Possible workaround: Add more force-inlines at some places.
Comment 2 Christoph Hertzberg 2019-11-01 09:33:42 UTC
Even more reduced example: https://godbolt.org/z/47AJDU
I.e., just a struct with four std::complex<double> does not get optimized away either when compiled in C++17 mode. 
I don't see any possible workaround, except storing `std::complex<double>[size]` as `double[2*size]` or trying to provide our own `Eigen::complex` type. Both sound like a lot of effort just for a workaround.

We may document this as "known issue" (not sure if anyone actually looks here):
http://eigen.tuxfamily.org/index.php?title=FAQ#Known_MSVC_issues
Comment 3 Gael Guennebaud 2019-11-14 16:52:53 UTC
I've added an entry to the FAQ. We cannot do better, so closing.
Comment 4 Nobody 2019-12-04 18:52:20 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1765.

Note You need to log in before you can comment on or make changes to this bug.