-
-
Notifications
You must be signed in to change notification settings - Fork 938
UniTask performance issue compared to Unity coroutines #662
-
Hello,
I’ve implemented a central scheduler-like functionality for games to avoid unnecessary repetitive code when adding coroutines or UniTasks.
Initially, my scheduler was internally using coroutines, but later I came across the UniTask package, so I ported the coroutines to use UniTasks.
Now, the issue is—after profiling both implementations to check runtime performance and GC allocations—the results show that UniTask is significantly more expensive than coroutines in terms of both CPU usage and GC allocations!
I’m attaching both the Coroutine-based and UniTask-based scheduler implementations, along with screenshots from the profiler.
The setup is simple: I’m just spawning 100 instances of the scheduler like this.
public class NewBehaviourScript : MonoBehaviour
{
public int schedulerInstances = 100;
private int counter;
private void Update()
{
if (counter < schedulerInstances)
{
Scheduler.StartFrameJob((deltaTime) => { });
counter++;
}
}
}
So, can someone tell me if I’m doing something wrong, or clarify how UniTask is supposed to be more efficient than coroutines? Or is there no comparison between the two, and it's just another plugin?
With Coroutine:
Using-Coroutine
With UniTask
Using UniTask
Coroutine scheduler: Coroutine-Scheduler.zip
UniTask scheduler: UniTask-Scheduler.zip
Beta Was this translation helpful? Give feedback.