Performance: Animation events
MEDIUM IMPACT
Animation events affect the frame rendering time and input responsiveness by adding callbacks during animation playback.
void OnAnimationEvent() {
// Just set a flag or enqueue a lightweight task
shouldLoadAsset = true;
}
void Update() {
if (shouldLoadAsset) {
StartCoroutine(LoadAssetAsync());
shouldLoadAsset = false;
}
}void OnAnimationEvent() {
// Heavy logic like loading assets or complex calculations
LoadLargeAsset();
PerformComplexCalculation();
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy logic in animation events | N/A | N/A | Blocks frame rendering causing jank | [X] Bad |
| Lightweight flag setting in animation events | N/A | N/A | Minimal impact on frame rendering | [OK] Good |