The ConcurrentDictionary type is optimized for concurrent key/value reads/write. The Count and Keys properties has inefficient locking mechanisms. Performing multiple operations on a ConcurrentDictionary also adds a performance penalty as each operation acquires and releases the locks. It would be much more efficient to acquire the locks required, then perform all the operations and then release.
The
ConcurrentDictionary
type is optimized for concurrent key/value reads/write. TheCount
andKeys
properties has inefficient locking mechanisms. Performing multiple operations on aConcurrentDictionary
also adds a performance penalty as each operation acquires and releases the locks. It would be much more efficient to acquire the locks required, then perform all the operations and then release.This has been reported in https://github.com/DuendeSoftware/Support/issues/1161.