Is it possible to improve performance by using PLINQ instead of a standard foreach when calling the same function on a bunch of objects.
Is this what the BroadcastMessage(…) does in the background?
Just curious to see what people think. Thanks.
Is it possible to improve performance by using PLINQ instead of a standard foreach when calling the same function on a bunch of objects.
Is this what the BroadcastMessage(…) does in the background?
Just curious to see what people think. Thanks.
using linq etc doesn’t help if the function thats called is the bomb as in case of broadcast which loops around and then uses SendMessage basically
Makes sense.
So if SendMessage() was a more expensive operation like an enemies decision making function it might be worth it?
I’m not very familiar with PLINQ yet so I’m trying to evaluate its relevance to game programming. I am used to threading and tasks, and it appears as PLINQ is just a combination of that with standard LINQ. So it looks like I might be able to put it to use.
Well
you can’t use PLINQ with unity, only LINQ. Unity does not allow threading with anything thats within the UnityEngine namespace (its not threadsafe)
In addition PLINQ is .NET 4 which is something not even supported by mono 2.6 on which unity bases (nor does it have the automagic loop parallelization of .NET 4)
using LINQ would only gain you very little if the function is the problem not the loop. What LINQ helps is if you have complex filter loops, even if it is at worst only on the readability and code length ![]()
OK thanks, that clears up a lot.