Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async UniTaskVoid allocates garbage in Build #566

Open
Guirie92 opened this issue Apr 9, 2024 · 0 comments
Open

async UniTaskVoid allocates garbage in Build #566

Guirie92 opened this issue Apr 9, 2024 · 0 comments

Comments

@Guirie92
Copy link

Guirie92 commented Apr 9, 2024

Hi, I've been doing quite some testing in the Unity Editor. In the documentation, it's mentioned that the AsyncStateMachine method may generate garbage only in the Editor since a class is used (for builds, there're no allocations since a struct is used instead). Then, it'd have to do the pooling, so the first time UniTask runs, it might allocate quite some garbage.

However, for subsequent calls to UniTask (async UniTaskVoid), I saw no garbage allocations in the Editor (0 B).

To my surprise, when building and testing, I see 88 B of garbage allocated per UniTask call, and it has nothing to do with AsyncStateMachine, or pooling promise objects. With the "Deep Profile" enabled, I only can see the call to the UniTask, and right below (inside the UniTask itself), I always get "GC.Alloc --> 88 B", with no further details.

The way I'm seeing this is by using something like this:

 private void TriggerUniTask()
 {
    TestUniTask(_taskVersion).Forget();
 }

 private async UniTaskVoid TestUniTask(int taskVersion)
 {
    while (Time.time - startTime < _animationTime)
    {
        if (taskVersion != _taskVersionScore) return;
        float progress = (Time.time - startTime) / _animationTime;

        // Do something that doesn't allocate garbage

        await UniTask.Yield();
    }
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant