FPS spikes even with no activity

Hi, I've built an AR app that has a simple objective, which is to play videos on top of detected images. The first part, building the logic, is mainly completed, and I have now moved on to the app optimization step, as I was noticing FPS spikes damaging the overall app experience.

To tackle this, I've tried building the app from the ground up and analyzing each step with the profiler to understand what is causing this generalized slowness. The weird thing that I am noticing now is that even with the simplest setup, after a few dozen seconds, the app will start losing more and more frames, making the experience pretty bad.

Just as an example, let's refer to the source code available here - https://github.com/dilmerv/UnityARFoundationEssentials/blob/master/Assets/Scripts/TrackedImageInfoRuntimeManager.cs (thanks Dilmerv!) - which basically instantiates a Reference Image Library at runtime and then uses the default "trackedImagePrefab" to instantiate an object at the detection of the image.

It is a simple setup and I would not expect that to overload the app execution, yet, when I run this on my phone, it starts lagging after 20-30 seconds, as you can see from the attached profiler:

Do you have any idea how this is cause? What are the best practices when it comes to AR apps that can lower the resource allocation and improve the FPS?

I suspect it has something to do with the AR Camera settings included in XR Origin?

Since this is a very simple setup, I've marked it as a Bug, but it's also a general question.
Looking forward to hearing from you.
Cheers

Did you check with deep profiling as well?
If it's on an up to date lts version you could make a bug report for this as well

This is what it looks like with the Deep Profiler and Script Debugging.
To reiterate, even without detecting an image and playing a video, the app drops frames and gets very slow in a matter or 20-30 seconds from booting.

9734194--1392040--Screenshot 2024-03-28 at 10.49.24.png

Could it be thermal throttling maybe?

You'd suggest trying out a different device? With now I'm using a Pixel 7, which should not be that bad.

A possible explanation for the CPU spikes even when nothing is happening could be due to C#'s garbage collection. (This is aside from aspects of your program that might be causing the slow performance overall).

1 Like

Does GarbaceCollection cause problems even when there are no objects to spawn/destroy?
In this case, there's literally no object in the scene until a tracked image is found.

For context, I do have "Incremental GC" enabled

9736969--1392607--Screenshot 2024-03-29 at 09.26.20.png

My code is all added to one object, the XR Origin. Could it be that the cause of the general lagginess?

Anyone? I don't understand how people can create complicated AR apps when even the most basic setups get my device (not an old device) to lose frames

Do you see the same issue if you replace the video with something like a cube? That will help narrow down if the issue is with AR or video playback.

1 Like

Oh yeah, I wouldn't consider an actively running video player to be "no activity" (even if you're not spawning or destroying any GameObjects). My prior comment about garbage collection was mostly in response to the title of the post. Narrowing down whether it's the video player or not that's causing the issue would be a good idea.