You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During one of the performance testing, found out that calling to ConcurrentDictionary.Count is contributing significant time to a hot path.
Configuration
win x64 .net8.0
Regression?
Dont think this is a regression.
Analysis
Looking into the implementation for Count, found out that each time Count is called, it is locking the entire dictionary and iterate through all buckets to get a sum.
It seems that the performance would be much better to keep an atomic counter so that get Count is instant.
Description
During one of the performance testing, found out that calling to
ConcurrentDictionary.Count
is contributing significant time to a hot path.Configuration
win x64 .net8.0
Regression?
Dont think this is a regression.
Analysis
Looking into the implementation for Count, found out that each time Count is called, it is locking the entire dictionary and iterate through all buckets to get a sum.
It seems that the performance would be much better to keep an atomic counter so that get Count is instant.
https://source.dot.net/#System.Collections.Concurrent/System/Collections/Concurrent/ConcurrentDictionary.cs,1116
The text was updated successfully, but these errors were encountered: