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):
Possible workaround: Add more force-inlines at some places.
Reported to Microsoft:
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):
I've added an entry to the FAQ. We cannot do better, so closing.
-- 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.