-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance Regression in Concurrent (Stack/Queue)? #61673
Comments
Tagging subscribers to this area: @dotnet/area-system-collections Issue DetailsHopefully this is the right place; short and sweet.... Description[MemoryDiagnoser]
public class CBench
{
private const int ITERATIONS = 10_000_000;
[Benchmark]
public void ConcurrentBag()
{
var collection = new ConcurrentBag<int>();
Parallel.For(0, ITERATIONS, i =>
{
collection.Add(i);
});
}
[Benchmark]
public void ConcurrentStack()
{
var collection = new ConcurrentStack<int>();
Parallel.For(0, ITERATIONS, i =>
{
collection.Push(i);
});
}
[Benchmark]
public void ConcurrentQueue()
{
var collection = new ConcurrentQueue<int>();
Parallel.For(0, ITERATIONS, i =>
{
collection.Enqueue(i);
});
}
} Data (.NET Framework 4.8)
Data ( .NET 6.0.0)
Haven't done much digging other than the above. Not really sure where to being; is there a guide for tracking down perf. regression - happy to get stuck in :) Regards,
|
Adding data for .NET Core 3.1.21. Data (.NET Core 3.1.21)
|
Adding data for .NET 5.0.12. Data (.NET 5.0.12)
|
Probably related: #56017 |
The only PR that touched it was #46120 (#46714 (comment)) |
Looks like the code can be made slightly better by not re-reading |
Hi everyone, this is my first active contribution - hope I can actually help :) I had a look at the ConcurrentStack. For me, it looks like the performance regression comes from a modification in the SpinWait. A test with a modified version of SpinWait gave similar results in net7 compared to net4.8. The modification is motivated by the diff of SpinWait to an earlier version in 2019 (7c0a404). Modification: private void SpinOnceCore(int sleep1Threshold)
{
//..
if (_count >= sleep1Threshold && sleep1Threshold >= 0)
{
Thread.Sleep(1);
}
else
{
//..
changed to private void SpinOnceCore(int sleep1Threshold)
{
//..
if (_count >= sleep1Threshold /*&& sleep1Threshold >= 0*/)
{
// Allow the sleep1Threshold with value -1 case
Thread.Sleep(1);
}
else
{
//..
|
Thanks for taking a look. cc: @kouvel |
Hopefully this is the right place; short and sweet....
Description
Data (.NET Framework 4.8)
Data ( .NET 6.0.0)
Haven't done much digging other than the above. Not really sure where to being; is there a guide for tracking down perf. regression - happy to get stuck in :)
Regards,
Indy
The text was updated successfully, but these errors were encountered: