Skip to content

Consider replacing SynchronizedDictionary with ConcurrentDictionary #743

@Youssef1313

Description

@Youssef1313

I think the BCL ConcurrentDictionary should be able to perform much better than the current SynchronizedDictionary implementation.

Using Moq, which depends on Castle.Core, I observe threadpool starvation in a parallelized test run. The threadpool threads are mostly in stack traces similar to this one:

Image
  • Using ConcurrentDictionary might lock less. I guess it creates some buckets per the hash code, and the different buckets get different locks, which allows for more concurrent access without breaking the type's thread safety.
  • Or, if you have other approaches where you can eliminate the need to lock altogether, that also might be a good option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions