ManagedStatic is slow at least on Windows because it calls sys::MemoryFence
on every access. MSVC profiler reported that LLD is spending 9% on this function.
This patch is to avoid using that wrapper class and use call_once instead.
Details
- Reviewers
• espindola
Diff Detail
Event Timeline
What is calling object::object_category so much that it can occupy 9% of the run time? If that code path is sufficiently common maybe it should just not be using "errors" in the first place.
Overall, just relying on thread-safe statics is preferable, but even then having so many non-inlined calls to this function in regular operation doesn't seem right.
I think originally the use of ManagedStatic was to work around that not all compilers supported thread-safe initialization of function local statics. Now that that works on all supported compilers, can you just write:
static _object_error_category Ret; return &Ret;
?
I agree that using function local static would be an improvement regardless of any speedup.
According to https://msdn.microsoft.com/en-au/library/hh567368.aspx#concurrencytable this works with MSVC 2015 and according to http://llvm.org/docs/GettingStartedVS.html we now required at least 2015.
LGTM witch a local static instead of a mutex.