Skip to content
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

Huge CPU usage since iOS 16.1 #17

Closed
Reactor13 opened this issue Dec 17, 2022 · 18 comments · Fixed by #18
Closed

Huge CPU usage since iOS 16.1 #17

Reactor13 opened this issue Dec 17, 2022 · 18 comments · Fixed by #18
Assignees

Comments

@Reactor13
Copy link

Huge CPU usage since iOS 16.1

Hi. Our users point that since iOS 16.1 our app with PiP drain battery very fast.

We had tested it. So. If PiP disabled then our app use about 2-5% CPU time. As soon as the PiP is turned on, the usage instantly grows to 110% - 130%.

We have changed the library code in such a way as to exclude any influence of our code. There was no content rendering for the test. Just a black window. And yet the load is the same 110% - 130%.

Can you confirm that you are experiencing the same issue? Is it library specific or is it a system bug. If this is a system bug, then let's create a defect in Apple Bug Tracker. Because iOS 16.2 has already been released, but the problem has not been solved.

@kleruk88
Copy link

we have the same problems

@Reactor13
Copy link
Author

we have the same problems

I have been tested it on latest XCode 14.2 on latest iOS 16.2. There is no result, still 110-130% CPU usage...

@kleruk88
Copy link

kleruk88 commented Dec 19, 2022

for example
PiP - ON
on background
PiP - Off
off background

@uakihir0
Copy link
Owner

@Reactor13 @kleruk88
Thanks for the report.
I will investigate, do you use uiPipView.startPictureInPicture(withRefreshInterval: ) to start PiP?

@uakihir0 uakihir0 self-assigned this Dec 19, 2022
@Reactor13
Copy link
Author

@Reactor13 @kleruk88 Thanks for the report. I will investigate, do you use uiPipView.startPictureInPicture(withRefreshInterval: ) to start PiP?

We have tried both modes. It doesn't affect. CPU usage increases in any case immediately after the appearance of the PIP window itself and even if it is not updated / rendered afterwards.

@Andrew5
Copy link

Andrew5 commented Jan 5, 2023 via email

@Reactor13
Copy link
Author

Any updates? News?

@Reactor13
Copy link
Author

iOS 16.3
problem still exists

@Reactor13
Copy link
Author

Just downloaded and ran the example from this project. All the same. After clicking Toogle PIP, the processor is loaded at 100%

Xcode 14.2, iOS 16.3, iPhone 14 Pro

@Reactor13
Copy link
Author

Снимок экрана 2023-02-06 в 14 57 20

@uakihir0
Copy link
Owner

uakihir0 commented Feb 8, 2023

Looking at the Profiler, CPU usage is not that much, but this is only the usage of the application, and when we look at the usage of the iPhone as a whole, it becomes a reasonably large usage rate as you have described. Below are the results from the Profiler, focused on PiP usage.

スクリーンショット 2023-02-08 18 51 18

On the other hand, when we look at the percentage of time elapsed in the application, the percentage of CPU usage is less than half of the problematic points, which means that the usage is not nearly as problematic as it could be. From this point of view, it seems likely that the cause is a change in the usage of threads per timer due to the OS version upgrade.

スクリーンショット 2023-02-08 18 48 54

@uakihir0
Copy link
Owner

uakihir0 commented Feb 8, 2023

If the code is modified not to render, TimeProfiler looks like the following, and the status remains the same. From this point of view, I think there is a problem in the usage of AVPictureInPictureController or it is a bug in the OS. I will investigate further.

スクリーンショット 2023-02-08 19 05 51

@uakihir0
Copy link
Owner

uakihir0 commented Feb 8, 2023

I have found that AVKit is consuming time during PiP, but I don't know how to control this.

スクリーンショット 2023-02-09 1 02 50

@Reactor13
Copy link
Author

@uakihir0 thank you for answer and investigation report.

@uakihir0
Copy link
Owner

uakihir0 commented Feb 9, 2023

Posted in forum.
https://developer.apple.com/forums/thread/724632

@eximpression
Copy link

eximpression commented Feb 9, 2023

Posted in forum. https://developer.apple.com/forums/thread/724632

From your post image we can see that the cpu time usage is conern with play timer, so I wondering that maybe CMTimeRange(start: .negativeInfinity, duration: .positiveInfinity) is the problem, so I change this line to CMTimeRange(start: .zero, duration: CMTimeMake(value: 3600*24, timescale: 1)).
guess what, the cpu usage is drop to 0!
so
func pictureInPictureControllerTimeRangeForPlayback(_ pictureInPictureController: AVPictureInPictureController) -> CMTimeRange {
CMTimeRange(start: .negativeInfinity, duration: .positiveInfinity)
}

is the problem. don't return negativeInfinity and positiveInfinity, just a finity value it is!

uakihir0 added a commit that referenced this issue Feb 9, 2023
@uakihir0
Copy link
Owner

uakihir0 commented Feb 9, 2023

@eximpression
Thank you, I have confirmed that the CPU usage will go down.

Fixed in #18.

@Reactor13
Copy link
Author

🔥 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants