I just added an entity component system to my game and as usual I tried to spread the cpu loading of the component updates across the available cores using Parallel.ForEach.
This screwed up the game horribly.
Ever 4-5 seconds I had a spike where the cpu just tanked. I tracked it down to garbage collection.
Watching the monitor you can see the base memory usage going up and up and the garbage collector firing a complete refresh every 4-5 seconds.
I looked at my code and couldn't find any major sources of garbage, so as a test I removed all usage of Parallel.ForEach.
The problem instantly went away.
I put it back in and tested in debug x86 and Release:x86
The pattern is exactly the same, though more pronounced in debug than release.
I am going to have to rewrite my ECS to use software threading, but I'm pretty pissed off. Parallel.ForEach is such a powerful methodology and I have used it a lot in C# outside monogame without ever having these issues.
Might be a good idea to look at what's going on.