Performance: Recompute legend only when required