GithubHelp home page GithubHelp logo

Comments (5)

xiangfan-ms avatar xiangfan-ms commented on August 15, 2024 3

FYI, I wrote a blog post on various ways to improve the compile time.
The one I suggested above (way 2 in the blog post) actually changes the semantics because in this library 'nameSingular' is a typedef, not a real type. And ADL won't find namespaceName (the real type is in the parent namespace 'units').
However, way 1 and way 3 should still be applicable. Way 3 is probably the best choice.

from units.

nholthaus avatar nholthaus commented on August 15, 2024

Microsoft is still investigating, but recommend compiling with the option /permissive-, which improves compile time by ~40%.

from units.

nholthaus avatar nholthaus commented on August 15, 2024

It appears that the code in the library introduces O(n^2) behavior.
In particular:
inline std::ostream& operator<<(std::ostream& os, const namespaceName::nameSingular ## _t& obj) { os << obj() << " "#abbreviation; return os; };
This pollutes the global namespace and will slowdown all calls to 'operator<<'.
The header adds several hundred overloads of operator<< to the global namespace and the compiler has to do overload resolution on each of them because of 'os << ...' in the function definition, the time complexity is O(n^2).
It is suggested to use the following instead (which should benefit all compilers):
namespace namespaceName {
inline std::ostream& operator<<(std::ostream& os, const nameSingular ## _t& obj) { os << obj() << " "#abbreviation; return os; };
}
Regarding why GCC is faster, it is likely related to the fact that VC keeps the default argument of template parameter as token stream and has to re-parse it every time we specialize a function. The function template called in the repro is the ctor in unit_t:
template<class Ty, class = typename std::enable_if<traits::is_scalar_unit::value && std::is_arithmetic::value>::type>
inline unit_t(Ty value) : nls(value) {};
We need to specialize it during the overload resolution of 'operator <<' to see whether the argument can be converted to 'namespaceName::nameSingular' (which is the specialization of unit_t).
The more memory usage is likely related to the decorated name which is larger than the one from other compilers.

from units.

mwu-tow avatar mwu-tow commented on August 15, 2024

Hi, author of the linked bug report here.
I just tested the latest v2.3.x branch ( ff94725 ) and the compile times are greatly improved for MSVC (about 5s down from 22s). And not only — my tests for g++ also showed ~2x improvement.

Thank you for acting so quickly on the issue!

from units.

nholthaus avatar nholthaus commented on August 15, 2024

from units.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.