-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AR Foundation iOS massive slowdown when using AsyncOperation #1113
Comments
Update: confirmed this is not editor version related. Same behaviour is present when downgrading the project to 2022.3.8f1. So it seems there is a difference in how the Windows editor and MacOS (M2) editor to build the project. |
Update 2: Also confirmed that the MacOS XCode project is different from the Windows one since it does not contain any warnings where this is the case for Windows. So there is in fact a difference between the two. |
Hi @VanIseghemThomas, we are aware of other issues when building AR Foundation apps for iOS from a Windows Editor. I recommend that you build for iOS from macOS machines for now. Thanks for filing this bug though-- we'll see how QA prioritizes this issue as it makes its way through the process. |
Hi @andyb-unity, thanks for reaching out. The problem is actually the opposite. We have no problems with the project that is built on Windows funny enough. It's the project built on MacOS that causes the above mentioned issue. |
Oh I see. This is the first I've heard of anything like this. Thanks for the detailed report. |
No problem, thanks for the quick response! Maybe it's worth mentioning I'm also using the Apple Silicon version of the Unity editor. Haven't tried running under Rosetta. Will see if this makes a difference when I get into the office on monday. |
Update: Same issue building under Rosetta. |
Found the native call under [DllImport("__Internal", EntryPoint = "UnityARKit_CpuImage_DisposeAsyncRequest")]
public static extern void DisposeAsyncRequest(int requestHandle); Unfortunately I cannot figure out where the external call is made to. I figure it's to For now I'll try and see if I can offload this Dispose call to another thread or something. Not sure what the best way of working around this would be yet. |
Bump, any updates on this? |
Update: revisited this and tried to fix this in our project, seems the profiler isn't telling the real story here. To debug this I went and did the old Debug.Log with stopwatches on all my operations. Narrowed it down to the When deploying the application to the iPad and doing nothing but running I'll be trying the regular |
Solved by using the |
I'm not initially concerned about the async overload taking longer-- that's the purpose of async, to schedule the work onto a background thread instead of blocking the main thread. I do find it concerning that it takes longer over time. If you file a new bug with this updated info, I'll see if we can bypass initial QA review and get it assigned to us. Apologies that QA still hasn't responded to your October bug report. |
Although I no longer work at Unity, I originally implemented the conversion functions and may be able to help explain.
As Andy says, ConvertAsync uses a single background thread, while Convert uses all available hardware threads. The timings you reported (Convert=15ms, ConvertAsync=70ms) is a ~4.5x difference, which is about what I would expect on an iPad. At the time I implemented it (cira 2018), the image sizes were small enough that ConvertAsync would usually take less than 1 frame to complete, so you could start the async conversion at the beginning of a frame and it would be done by the end. Today, the camera images that both ARCore and ARKit provide are much larger, and the single-threaded conversion can take much longer than a frame. If you need to process every image, that's not good enough. If the synchronous Convert works for you, then I would just stick with that. If that takes up too much of your frame budget, I think Convert might actually be thread-safe, so you could try spinning up a C# thread and call it from there, e.g., Task.Run. Unity would need to confirm that though. If you really want to get your hands dirty, you can write your own conversion routine using Unity's Job System and
This is likely due to thermal throttling. Running ARKit for 10 minutes will cause the device to heat up and iOS will start throttling the CPU cores. So I think this is the expected behavior. Hope that helps! |
Initially I was in fact under the impression that the Dispose call for the AsyncConversion was the problem (see my initial screenshots). Not sure why the profiler reported that. I would also assume that it shouldn't take that long, so I'm not under the impression that that is in fact the underlying problem here.
Ok, given what @andyb-unity said above this makes sense. But I'm still not sure why the exact same version built on a Windows machine has much better performance. So I'm still under the impression that something is not running like it's supposed to. Any idea why that could be the case?
This was actually the next thing I am in the process of trying 😄. Initially I only did this for the actual processing for the converted image assuming this was the processing intensive part. To my surprise it was not.
Looked into this, but the documentation does not recommend having long running jobs, that's why I went for creating a thread.
This makes a lot of sense. However I was surprised to see such a drastic slowdown.
This is very helpful and gives a lot more insight, thanks! |
Not sure if I missed this, but it might be a good idea to include this in the documentation.
What would be the best way to report this. It essentially comes down to the fact that the AsyncConvert has poor performance when built om MacOS vs Windows machines. The difference between the Convert and AsyncConvert makes sense now, but there is still a very noticeable difference between the platforms. Best way to investigate would just be to build a simple application that fetches and converts the images and benchmark the 2 builds. |
https://unity.com/releases/editor/qa/bug-reporting. Send us the bug number you get from this process. Should be of the form IN-XXXXX. |
Unity bug report case number
IN-58003
Describe the bug
When disposing a AsyncOperation on Unity 2022.3.11f, this causes a massive slowdown.
To Reproduce
Steps to reproduce the behavior:
Call the following as a coroutine
This is stripped down code of what I'm actually doing, so might have some issues. The XRCpuImage is grabbed somewhere else and passed to this function.
Expected behavior
Dispose should not cause such a drastic slowdown. This was not a problem when building in 2022.3.8f1 on Windows 11
Actual behavior
A clear and concise description of what actually happened.
Smartphone (please complete the following information):
EDIT:
The problems does not seem to be the Dispose call but the Convert operation. Not sure why the profiler is reporting something else here. See the thread for more information
The text was updated successfully, but these errors were encountered: