Performance: Async/await in Unity
MEDIUM IMPACT
This affects how Unity handles asynchronous tasks without blocking the main thread, improving frame rate and responsiveness.
async void Update() { await HeavyTaskAsync(); // runs asynchronously without blocking } async Task HeavyTaskAsync() { await Task.Delay(2000); // non-blocking delay }
void Update() {
HeavyTask(); // runs synchronously and blocks main thread
}
void HeavyTask() {
// simulate heavy work
Thread.Sleep(2000);
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous heavy task | N/A | Blocks main thread causing frame drops | High paint cost due to frame skips | [X] Bad |
| Async/await with Task.Delay | N/A | No blocking, smooth frame updates | Low paint cost, smooth rendering | [OK] Good |