async UniTaskVoid allocates garbage in Build
Guirie92 opened this issue · 1 comments
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();
}
}
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.