Hi there,
performance wise which approach is better in new unity? async await where i create TaskCompletionSource everytime i use it generating garbage or callback Acton approach?
Please advise
Hi there,
performance wise which approach is better in new unity? async await where i create TaskCompletionSource everytime i use it generating garbage or callback Acton approach?
Please advise
If something is better or more performant depends on the use case and can’t be answerd properly without further context.
Btw callbacks can also generate garbage, depending on how you pass the callback.
Callbacks and async await are often not interchangable, even though the second was kinda made to replace the first.
Async await is often used with http requests, file loading, scene-loading, addressables etc. and such things don’t support callbacks.
In other cases, offhand, callbacks seems to be slightly faster and less garbage intensive, but I advice you to profile for your specific case.
In my experience, any operations involving any of them are usually rare so I go with async await (UniTask), because there’s old thing called “callback hell”, and I don’t want to make already complex logic even more complex.
Can you please share the difference with code?
Thanks, so to avoid callback hell , async/await with uni task is better approach.
Like they said we’d need to know the context. Programming is rarely “x is always better than y”.
Async and callbacks have different use-cases, imo. Use either where appropriate.
Some games might benefit from a functional-oriented programming style, but it’s very all-encompassing as you need to be using async top-to-bottom.