This is an archive of the discontinued LLVM Phabricator instance.

Don't use ManagedStatic.
AcceptedPublic

Authored by ruiu on Jun 8 2015, 12:36 AM.

Details

Reviewers
espindola
Summary

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.

Diff Detail

Event Timeline

ruiu updated this revision to Diff 27282.Jun 8 2015, 12:36 AM
ruiu retitled this revision from to Don't use ManagedStatic..
ruiu updated this object.
ruiu edited the test plan for this revision. (Show Details)
ruiu added a reviewer: rafael.
ruiu added a subscriber: Unknown Object (MLST).
silvas added a subscriber: silvas.Jun 8 2015, 7:45 PM

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.

espindola edited reviewers, added: espindola; removed: rafael.Mar 15 2018, 10:59 AM

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;

?

espindola accepted this revision.Mar 15 2018, 2:16 PM

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.

This revision is now accepted and ready to land.Mar 15 2018, 2:16 PM