Skip to content

Faster thread local statics #63619

@EgorBo

Description

@EgorBo

I noticed that various Thread Statics helpers constantly pop up in native traces in micro and macro benchmarks, e.g. Platform-JSON TE benchmark:
image

A simple demo:

while (true)
{
    var arr = ArrayPool<int>.Shared.Rent(10000);
    ArrayPool<int>.Shared.Return(arr);
}

when it spins it spends most of the time in JIT_GetSharedGCThreadStaticBaseDynamicClass:
image
where it just early outs:
image

if only we had a dedicated register (I think we can afford one at least on arm) which always pointed to current thread we could avoid that kind of overhead. Something like this (pseudocode):

if (!CTreg->tlsInited)
  initTls();
var field = CTreg->field;

making TLS access super cheap. As a bonus it might help with some pinvoke/safepoints routine?
Thoughts?
cc @jkotas

category:cq
theme:runtime
skill-level:intermediate
cost:small
impact:medium

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMItenet-performancePerformance related issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions