Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Perf: Interlocked.Exchange should special-case nullptr values #69000

@GrabYourPitchforks

Description

@GrabYourPitchforks

If you look at the callers of Interlocked.Exchange<T>(ref T, T), you'll notice that a large number of them pass nullptr as for the second parameter.

The method currently always results in a call to the native runtime, where the thread is notified of object assignment and the card table is updated if needed. However, if the value is known at JIT time to be nullptr, both of these steps can be skipped. This would allow the JIT to emit an xchg instruction directly into the codegen, avoiding the call back into the runtime. There's a similar optimization in place today when assigning a known-nullptr value to a field; the JIT emits the mov instruction directly without bouncing through the internal "volatile write & update card table" helper.

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

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions