On Wed, 28 Jun 2023, 10:53 Breno Guimarães via Std-Proposals, <std-proposals@lists.isocpp.org> wrote:
I think you need an actual benchmark to be able to claim the performance quality of the implementation.

For example, wouldn't it be better to just have as "isInitialized" thread local boolean and to access the object, you do:


thread_local bool isInitialized = false;
T& initialize() // mark with attribute to never inline
{
    Emplace on optional with call_once (typing on my phone :) )
    isInitialized = true;
    Return *g_obj;
}

inline T& g_obj_fn() {
     if (isInitialized) // mark this with likely attribute
        return *g_obj:
    else return initialize();
}

Then all access to the variable just need to check a boolean (in the hot path) instead of calling an opaque function.

I also don't see the need for a mutex on the initialization. The global call_once flag should be enough. The thread local variable shouldn't need to be atomic either.

And what has all this code got to do with std -proposals?