Jump to content

Unity plugin Garbage Collector allocations


Recommended Posts

Hey guys.


Where should I report GC allocations to make sure they will be fixed in upcoming SDK updates?


I found these allocations which occur every frame, allocating for GC  at the rate of 1.6 KB per frame:



Class: WaveVR\Scripts\WaveVR_Render.cs

Method: private IEnumerator RenderLoop()

Line: var wait = new WaitForEndOfFrame();



This allocates heap memory each time WaitForEndOfFrame instance is created.

Please cache it at the private class field and instantiate only once, then just reuse:


private WaitForEndOfFrame cachedWaitForEndOfFrame;// ...private IEnumerator RenderLoop(){    if (cachedWaitForEndOfFrame == null)    {        cachedWaitForEndOfFrame = new WaitForEndOfFrame();    }    yield return cachedWaitForEndOfFrame;    // ....}



Class: WaveVR\Scripts\WaveVR_Render.cs

Method: private void RenderEye(Camera camera, WVR_Eye eye)


WaveVR_Utils.Trace.BeginSection("Render_" + eye);Log.gpl.d(LOG_TAG, "Render_" + eye);


String concatenation implicitly leads to the String.Concat() call and it allocates memory on heap too.

Please avoid string concatenation each frame, and cache concatenated value for reuse outside the main loop.


Class: WaveVR\Scripts\WaveVR_Distortion.cs

Method: public void RenderEye(WVR_Eye eye, RenderTexture texture)

Line: WaveVR_Utils.Trace.BeginSection("Distortion_" + eye);



Same as previous, string concatenation.


 please let me know if it's possible to pass this to the Unity plugin devs, as per-frame allocations absence is very crucial for the smoothness of the VR experience - unfortunately Unity still uses old GC which collects garbage on main thread and this takes a lot of time leading to the performance drops (cpu usage spikes) which is very noticeable when doing anything in VR.



Link to comment
Share on other sites

  • 11 months later...

I'm still getting 2.2KB of garbage generated every frame by the RenderLoop coroutine (using WaveSDK 3.0.2) when testing on the headset. It is the only source of garbage collection at runtime in my project, and it causes dropped frames every couple seconds, so it's very important to fix this. What's your ETA on this fix?

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...