-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
area-System.ThreadingquestionAnswer questions and provide assistance, not an issue with source code or documentation.Answer questions and provide assistance, not an issue with source code or documentation.
Milestone
Description
Reading https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-9/#threading i'm wondering if instead of replacing lock(_lock) with _lock.EnterScope() ... Dispose the compiler shouldn't actually use something like:
_lock.Enter();
try
{
...
}
finally
{
_lock.Exit();
}
This prevents the allocation of the scope struct and in my benchmarks:
[Benchmark]
public void WithLock()
{
lock (_lock)
{
_value++;
}
}
[Benchmark]
public void WithLock2()
{
_lock2.Enter();
try
{
_value++;
}
finally
{
_lock2.Exit();
}
}
this performs ~5% better.
punchready
Metadata
Metadata
Assignees
Labels
area-System.ThreadingquestionAnswer questions and provide assistance, not an issue with source code or documentation.Answer questions and provide assistance, not an issue with source code or documentation.