[libcxx-commits] [libcxx] [libc++] Speed up classic locale (PR #72112)

Dmitry Vyukov via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 16 23:32:21 PST 2023


================
@@ -538,16 +549,40 @@ locale::__imp::use_facet(long id) const
 
 // locale
 
+std::atomic<locale::__imp*> locale::__imp::classic_;
----------------
dvyukov wrote:

I've considered this and specifically did with the additional variable for performance reasons.
There is no cost for atomic relaxed loads. On any sane architecture it's a normal load.
While the access to the local static object with dynamic initialization will incur:
1. An atomic acquire load (which is costlier and arm64).
2. A branch to handle the lazy dynamic initialization.
3. The indirection to load imp pointer from the classic locale object, so an additional cache line touched and a potential cache miss/eviction.

https://github.com/llvm/llvm-project/pull/72112


More information about the libcxx-commits mailing list