Skip to content
  • Igor Kushnir's avatar
    Make DUChainReferenceCounting instance inline function-local static · 52216a13
    Igor Kushnir authored
    MSVC intentionally does not support DLL import/export of thread_local
    variables. The result is the following compilation error:
    C:\CI\Job Build\kdevplatform\serialization\referencecounting.h(57): error C2492:
    'duchainReferenceCounting': data with thread storage duration may not have dll interface
    
    In addition, this inline function-local static version unexpectedly
    turned out to be much faster than the previous exported extern variable
    version. The following table compares performance of the past, current
    and considered alternative implementations in the affected benchmarks.
    The numbers denote milliseconds per iteration.
    
    version\benchmark       qhash   create  destroy shouldDo(-) shouldDo(+)
    no thread_local         0.67    136     50      70          3146
    bool thread_local       1.0     144     85      247         3294
    exported thread_local   1.4     151     121     636         707
    internal linkage        1.5     151     131     883         1025
    non-inline f-l static   1.5     152     138     954         1060
    inline variable         1.2     147     107     388         459
    inline f-l static       1.2     149     103     212         318
    
            Legend
    Benchmarks:
    qhash       - BenchIndexedString::bench_qhashIndexedString()
    create      - BenchIndexedString::bench_create()
    destroy     - BenchIndexedString::bench_destroy()
    shouldDo(-) - BenchItemRepository::shouldDoReferenceCounting(disabled)
    shouldDo(+) - BenchItemRepository::shouldDoReferenceCounting(enabled)
    
    Versions:
    no thread_local         - 8fca91a0
    bool thread_local       - db67d592
    exported thread_local   - the version just before this commit
    internal linkage        - static thread_local variable in the cpp file
    non-inline f-l static   - instance() defined in the cpp file
    inline variable         - inline thread_local variable in the header
    inline f-l static       - this commit
    52216a13