Performance: Why coroutines handle time-based logic
MEDIUM IMPACT
This affects how smoothly time-based actions run without blocking the main game loop, impacting frame rate and responsiveness.
IEnumerator WaitAndDo() {
yield return new WaitForSeconds(delay);
// continue logic
}
void Start() {
StartCoroutine(WaitAndDo());
}void Update() {
if (Time.time < startTime + delay) {
// busy wait, do nothing
} else {
// continue logic
}
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Busy wait in Update loop | N/A | Blocks frame updates | Causes frame drops | [X] Bad |
| Coroutine with WaitForSeconds | N/A | No blocking | Smooth frame rendering | [OK] Good |