dotnet / dotnet/aspnetcore

Use System.Threading.Lock throughout ASP.NET Core

Open
#56,794 3 comments 9 reactions 0 assignees View on GitHub
area-networking Perf
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

.NET 9 added a new lock type: https://github.com/dotnet/runtime/issues/34812. The benefits are some small performance improvements, and disambiguation about locking on any type.

We should see if we can use this in ASP.NET Core. Could be performance gains in lock heavy code.

### Describe the solution you'd like

The new type is only available in .NET 9 or later. However, some ASP.NET Core code targets back to .NET standard. It's not as simple as updating `private static readonly object _lock` fields with the `Lock` type because of this.

We could add a shim `Lock` type that is conditionally included in older targets. A shim type would avoid spreading `#ifdefs` throughout the code.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.