Skip to content

Commit

Permalink
Merge pull request #161 from Jakub-Krakowiak/feature/rgl-reduce-garba…
Browse files Browse the repository at this point in the history
…ge-collection

Performance increase for RGLUnityPlugin by reducing garbage collection
  • Loading branch information
mackierx111 authored Jul 31, 2023
2 parents 3bfd988 + b6647b7 commit fdbb880
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Assets/RGLUnityPlugin/Scripts/SceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ public void DoUpdate()
SynchronizeSceneTime();

Profiler.BeginSample("Find changes and make TODO list");
var thisFrameGOs = FindObjectsOfType<GameObject>()
.Where(go => go.activeInHierarchy)
.Where(go => go.GetComponentsInParent<LidarSensor>().Length == 0);
var thisFrameGOs = new HashSet<GameObject>(FindObjectsOfType<GameObject>());
thisFrameGOs.RemoveWhere(IsNotActiveOrParentHasLidar);

// Added
var toAddGOs = new HashSet<GameObject>(thisFrameGOs);
Expand All @@ -160,7 +159,7 @@ public void DoUpdate()
.Except(toRemove).ToArray();
RGLObject[] toSkin = existingToSkin.Concat(newToSkin).ToArray();

lastFrameGameObjects = new HashSet<GameObject>(thisFrameGOs);
lastFrameGameObjects = thisFrameGOs;
Profiler.EndSample();

Profiler.BeginSample("Add new textures");
Expand Down Expand Up @@ -548,5 +547,10 @@ private static void AddTextures(IEnumerable<RGLObject> rglObjects)
sharedTexturesUsageCount[textureID] += 1;
}
}

private static bool IsNotActiveOrParentHasLidar(GameObject gameObject)
{
return !gameObject.activeInHierarchy || gameObject.GetComponentsInParent<LidarSensor>().Length != 0;
}
}
}

0 comments on commit fdbb880

Please sign in to comment.