-
Notifications
You must be signed in to change notification settings - Fork 434
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
Perf/faster full tree visit #7692
Conversation
int newSlot = Interlocked.Decrement(ref _slots); | ||
if (newSlot < 0) | ||
{ | ||
Interlocked.Increment(ref _slots); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be done better with voliatale
? @Scooletz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can't easily as you want to undo the previous Decrement
in an atomic way. You'll need at least one CAS to get it. The case here though is that on faults, you do two CAS operations. In such scenarios you could
var counter = Volatile.Read(ref _slots)
if (counter <= 1)
{
return false;
}
if (Interlocked.CompareExchange(ref slots, counter -1, counter) == counter))
{
return true;
}
// slow path in the contended scenario, with loop retry
The question is how contended it is and how likely it's to hit the condition of returning false.
}); | ||
} | ||
|
||
if (tasks != null && tasks.Count > 0) Task.WaitAll(tasks.ToArray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (tasks != null && tasks.Count > 0) Task.WaitAll(tasks.ToArray()); | |
if tasks?.Count > 0) Task.WaitAll(tasks.ToArray()); |
Also we can use do AsSpan()
instead of ToArray
in .net 9 (update #7585 when this is merged to master)
Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
Co-authored-by: Szymon Kulec <scooletz@gmail.com>
Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
Types of changes
What types of changes does your code introduce?
Testing
Requires testing
If yes, did you write tests?
Notes on testing