I'm using XNA and all of my drawing is done in the main thread. I am CPU-bound and I thought I could gain performance by moving some non-update logic (like animation update) from the update loop into the draw loop and performing it in a parallel thread. This is the pseudocode:
Before:
void Update()
{
foreach (var model in AllGameModels)
model.UpdateAnimation();
}
After:
void UpdateAnimation()
{
foreach (var model in AllGameModels)
model.UpdateAnimation();
}
Thread UpdateAnimationThread;
void Draw()
{
if (UpdateAnimationThread != null)
UpdateAnimationThread.Join();
UpdateAnimationThread = new Thread(UpdateAnimation);
[main Draw code follows]
}
Unfortunately this always results in a significant DROP in performance. What can I be doing wrong? There is NO multithreading code in the Draw loop as it is simply impossible to do and I am not missing anything.