uakihir0 / UIPiPView

This library is a UIView that is capable of Picture-in-Picture (PiP) in iOS.
MIT License
216 stars 32 forks source link

Huge CPU usage since iOS 16.1 #17

Closed Reactor13 closed 1 year ago

Reactor13 commented 1 year ago

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 commented 1 year ago

we have the same problems

Reactor13 commented 1 year ago

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 commented 1 year ago

for example PiP - ON

on background

PiP - Off

off background
uakihir0 commented 1 year ago

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

Reactor13 commented 1 year ago

@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 commented 1 year ago

How do I control the display size of picture in picture and display it on the interface with my camera?Object-C代码

Reactor13 @.***> 于2022年12月18日周日 04:49写道:

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.

— Reply to this email directly, view it on GitHub https://github.com/uakihir0/UIPiPView/issues/17, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAYXPMNLIPO5APLIMHDSN6DWNYRNXANCNFSM6AAAAAATCEDRYA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Reactor13 commented 1 year ago

Any updates? News?

Reactor13 commented 1 year ago

iOS 16.3 problem still exists

Reactor13 commented 1 year ago

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 commented 1 year ago
Снимок экрана 2023-02-06 в 14 57 20
uakihir0 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@uakihir0 thank you for answer and investigation report.

uakihir0 commented 1 year ago

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

eximpression commented 1 year ago

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 commented 1 year ago

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

Fixed in https://github.com/uakihir0/UIPiPView/pull/18.

Reactor13 commented 1 year ago

🔥 Thank you!