Skip to content

Commit

Permalink
Remove unnecessary per-frame allocation.
Browse files Browse the repository at this point in the history
UIParticle.UpdateRenderers() produces a sizable per-frame allocation due to the use of LINQ's Any() method. Replacing said method usage with a simple foreach loop entirely removes the allocation and reduces over all GC pressure.
  • Loading branch information
jakeoconnor-peoplefun authored and mob-sakai committed Aug 15, 2023
1 parent 399c165 commit c984886
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Scripts/UIParticle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,13 @@ internal void UpdateRenderers()
{
if (!isActiveAndEnabled) return;

if (m_Renderers.Any(x => !x))
foreach (var rend in m_Renderers)
{
RefreshParticles(particles);
if (!rend)
{
RefreshParticles(particles);
break;
}
}

var bakeCamera = GetBakeCamera();
Expand Down

0 comments on commit c984886

Please sign in to comment.