Reduce startup time.#1288
Conversation
|
I think @Adlai-Holler mentioned that dispatch_once is faster than function local static because the latter uses a global mutex for all statics. Maybe switch to dispatch_once to get the tiny perf gain? |
Make global static a function local static. This stops it from being initialized premain and affecting startup time.
|
I would be interested to get some benchmarks numbers around this area. @dmaclach Did you profile by any chance? Looking at http://www.modernescpp.com/index.php/thread-safe-initialization-of-a-singleton it seems static vars with block scope is faster as using |
|
I looked a bit more into benchmarking C++ static variables with block scope and dispatch_once initialization. Here is a small benchmark script and the results running it three times at the end. Pretty interesting based on the results we probably should go with Runs:1. Run:2. Run:3. Run: |
|
Also interesting moving this to multithreading access via 1. Run2. Run: |
|
Thanks folks. Moved over to dispatch_once. |
|
Very interesting numbers, thanks for sharing @maicki. |
|
FWIW https://opensource.apple.com/source/libcppabi/libcppabi-26/src/cxa_guard.cxx.auto.html Is how the static initialization is done. There does appear to be at large recursive lock. |
|
cool stuff! |
|
@maicki can you merge? I do not have privs. |
Make global static a function local static. This stops it from being initialized premain and affecting startup time. (cherry picked from commit 7cddc2b)
Make global static a function local static. This stops it from being initialized premain and affecting startup time.