Make entities fully thread-safe
Created by: uwx
Summary
Fixes #219 (closed), fixes #410 (closed).
Details
I just converted a bunch of properties from lists into concurrent dictionaries. A custom JsonConverter was used for the properties to avoid monstrous amounts of custom deserialization code.
There isn't much to say here besides that there is a very large margin for error so please review this PR with care. Also, there should be a predictable performance boost rather than a slowdown from these patches since many, many lookups have gone from O(n) (FirstOrDefault) to O(1) (TryGetValue). As a minor thing, wherever ToDictionary was previously used, expect major memory usage improvements at zero performance cost.
Changes proposed
- Make DiscordClient.Guilds and PrivateChannels into ConcurrentDictionary instances
- Make DiscordGuild.Members, Channels, VoiceStates, Emojis and Roles into ConcurrentDictionary instances
- Optimize lookups where appropriate
- Create ReadOnlyConcurrentDictionary
- Touch up bits of ReadOnlySet to be consistent
- Create SnowflakeArrayAsDictionaryJsonConverter
Notes
This PR has conflicts with my other PR. Please merge this one first.