Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

UniTask performance issue compared to Unity coroutines #662

SudarshanShetty1796 started this conversation in General
Discussion options

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

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /