Comments (5)
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.
Microsoft is still investigating, but recommend compiling with the option /permissive-
, which improves compile time by ~40%.
from units.
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.
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.
from units.
Related Issues (20)
- 2.3.2 Fails to compile HOT 2
- Conan package out of date HOT 2
- Undefined references to .name() and .abbreviation() HOT 1
- Incorrect enable_if condition for operator+ HOT 1
- Request for branch and pull request permissions HOT 5
- percent_t FROM double and TO double are different HOT 9
- 2.3.3 does not compile
- Add a way to specify units when "downcasting" to numeric type HOT 2
- Support the MSFS SDK HOT 2
- Empty base class optimization for MSVC
- Does not compile with GCC 12 HOT 1
- raw() and value() is error prone HOT 4
- [Bug] i386 (32-bit) fails to compile
- Shouldn't the naming of units::torque::foot_pound be changed
- v2 -> v3 porting HOT 2
- Need help implementing resistance as a new custom unit. HOT 2
- unit conversion emits a surprisingly high amount of instructions
- Compilation under MINGW
- Math functions not compatible with percent HOT 1
- Status of the project HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from units.