cancel
Showing results for 
Search instead for 
Did you mean: 

Unity tip: Enable IL2CPP for performance gains

l0g1k
Protege
I only recently realised I could use this feature, and turning it on reduced the CPU time for the OvrAvatar update loop from 1.5 ms to around 0.8 ms  - saving around 0.7 ms per avatar on an S6. If you don't know, it translates C# to native binaries. There is a lot of really slow MS native inter-op code in the Avatar SDK that seems to have benefited a lot from that.

Hopefully this helps someone else. Make sure you use a late-2017 or newer Unity as there were lots of bugs floating around before then I think.

PS: Another tip for lowering processing on lower end devices is that if the user does not have a controller connected, and is alone in the scene, you can disable OvrAvatar completely and save a bit of time, since the avatar is likely not doing anything in the scene at that point anyway (unless you have other cameras for some reason).



2 REPLIES 2

Preston_Jong
Protege
I will for sure try this.   I'm always looking for ways to optimize.   My game right now maintains 90 FPS, but the headroom is around 3% to 15% with an NVIDIA 1070.   And on my transition scenes I'll disable the OVRAvatar completely.   Thanks for the tips.

l0g1k
Protege


Thanks for your feedback and contribution to this forum!


Thanks!

As follow-up there is some small change needed to the AvatarSDK usage to support this

Find the method "MicFilter" and add this attribute " [MonoPInvokeCallback(typeof(CAPI.FilterCallback))]". (Add "using AOT;" to the file)

Please note the MicFilter content might have changed by the time you read this so don't copy/paste; just find it and add the attribute like so
[MonoPInvokeCallback(typeof(CAPI.FilterCallback))]
public static void MicFilter(short[] pcmData, System.UIntPtr pcmDataLength, int frequency, int numChannels)
{
float voiceMax = 0.0f;
float[] floats = new float[pcmData.Length];
for (int n = 0; n < pcmData.Length; n++)
{
float cur = floats = (float)pcmData / (float)short.MaxValue;
if (cur > voiceMax)
{
voiceMax = cur;
}
}
voiceCurrent = voiceMax;
}