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

AK 4.7 excessive CPU usage and audio sputtering. #1763

Closed
WholeCheese opened this issue Apr 30, 2019 · 20 comments
Closed

AK 4.7 excessive CPU usage and audio sputtering. #1763

WholeCheese opened this issue Apr 30, 2019 · 20 comments
Assignees

Comments

@WholeCheese
Copy link

I have been comparing CPU usage between Audiokit 4.7 and 4.6.4. I confess that my app may be pushing things to a limit but it has been working very well so far with AK 4.0 and just recently AK 4.6.4.

My app simulates wind chimes by additive sine wave synthesis. I am testing the CPU usage on two chimes:

A simple chime that plays 7 notes and a more complex chime set with 23 notes.

The simple 7 note chime uses a sound with 3 oscillators and envelopes for each note. In total, that's 8 mixers, 21 oscillators and 21 envelopes.

The complex chime uses 23 notes with 28 mixers, 75 oscillators, and 75 envelopes.

AK 4.0.4 and AK 4.6.4 are roughly equivalent but there is a huge difference between AK 4.6.4 and 4.7.

Simple Chime

  • AK 4.6.4 - average 19% (similar to AK 4.0)
  • AK 4.7 - average 41%

Complex Chime

  • AK 4.6.4 - average 44% (similar to AK 4.0)
  • AK 4.7 - average 65% with audio sputtering

The excessive CPU usage is a problem since I expect my app to be played in the background and iOS will generally kill apps in the background that use too many resources.

The audio sputtering is the real problem.

Since AK 4.6.4 does not exhibit any more CPU usage than AK 4.0.4, I am assuming that something bad has creeped into the AK 4.7 code.

Suggestions??

@aure
Copy link
Member

aure commented Apr 30, 2019

This is an amazingly well crafted and helpful issue, thank you. We have to figure out what has caused such a big change. We have the firepower to figure it out. :) @megastep @eljeff @sieren @dave234

@WholeCheese
Copy link
Author

Glad to help! :-) But, sorry to say I will be out of town and basically off the grid for the next two weeks and can't compute again until May 16. I trust your firepower will figure it out!

@sieren
Copy link
Contributor

sieren commented May 2, 2019

@WholeCheese can you give us some insights on how you're generating those sine waves?
I'm thinking we should setup a small test-app where we can swap out AK versions to bisect where the problem originated.

@WholeCheese
Copy link
Author

WholeCheese commented May 2, 2019 via email

@sieren
Copy link
Contributor

sieren commented May 2, 2019

Cool! That'd good to know. I'll ping @aure directly and will get it from him

@sieren
Copy link
Contributor

sieren commented May 11, 2019

I'm looking at the PlayChime App right now and I get roughly 20% on an iPhone 8 with the most complex setting (and that's in Debug mode as well).

On first look I couldnt find anything suspicious.

Which device were you using and are your measurements in line with the sample app?

@WholeCheese
Copy link
Author

WholeCheese commented May 12, 2019 via email

@aure
Copy link
Member

aure commented May 16, 2019

@WholeCheese when you're back I'd love to do a screenshare with you to look at the two version of your code with 4.6 and 4.7 to see the change in cpu usage first hand.

@aure
Copy link
Member

aure commented May 16, 2019

But, I'll close this as an issue until we can make it actionable. Look forward to working with you and @sieren and @megastep directly.

@sieren
Copy link
Contributor

sieren commented May 16, 2019

It'd be great if we could all get on a Slack call and do some screen sharing

@WholeCheese
Copy link
Author

WholeCheese commented May 17, 2019

Back from vacation and looking at the CPU usage difference between AK 4.6.4 and AK 4.7 with the PlayChime demo app. Attached is the demo app and two screen shots showing the CPU usage: one for AK4.6 and one for AK4.7. There were no changes to the demo code other than linking with one AK or the other. The two blips at the beginning of the CPU graph are from selecting the "Alto" chime, or number 4 in the segmented controller UI. The long blip happens in the AURemoteIO thread after hitting "Play"

This was run on a iPhone 5S and iOS 11.3.

PlayChime-4.6.zip

PlayChime-4 7

PlayChime-4 6

@aure aure reopened this May 17, 2019
@aure
Copy link
Member

aure commented May 18, 2019

I do not see this problem when running your code. I wonder if someone else on the team can corroborate my findings or yours:

image

image

@aure
Copy link
Member

aure commented May 18, 2019

Oops, my tests were on the simulator. I'll test on a device now.

@aure
Copy link
Member

aure commented May 18, 2019

On an iPhone X, iOS12.2. I do not have an iOS11 device, but I wouldn't be surprised if AudioKit 4.7 is optimized for iOS12.

image

image

@WholeCheese
Copy link
Author

WholeCheese commented May 18, 2019 via email

@aure
Copy link
Member

aure commented May 18, 2019

Here it is on an iOS11.4 simulator (I don't have an actual device on iOS11).

image

image

@aure
Copy link
Member

aure commented May 18, 2019

My feeling is that 28% on an iPhone X is probably about 67% on the iPhone 5s. So, that would say that I haven't been able to get the improved 20% on the iPhone 5s ie say 7% on an iPhone X. I would love to get that kind of performance boost.

@WholeCheese
Copy link
Author

Oh, dear. This was my blunder. Many, many sincere apologies!!

My AK4.6.4 project settings for Clang and Swift optimization (debug build) were set to -O3 and -O respectively. The AK4.7 Clang and Swift optimization settings (debug build) were -O0 and -Onone

Changing AK4.7 to fastest to match 4.6.4 results in nearly identical CPU usage.

I don't recall setting the optimization options but the finger appears to point in my direction?

As to why my AK4.6.4 project was set to Swift 4.2, again, I don't recall changing that, and actually had the impression that the move to Swift 5.0 started with AK4.7. AK4.6.4 builds fine with 5.0 but that had little if any effect on the CPU usage.

I am truly sorry about calling for this witch hunt. Please don't exile me from the club!!

@sieren
Copy link
Contributor

sieren commented May 18, 2019

Haha oh no! I actually mentioned that as a possibility to @aure but figured that's the first place you might have looked hehe.

Glad you got it solved! :)

@aure aure closed this as completed May 18, 2019
@aure
Copy link
Member

aure commented May 18, 2019

No worries. Its always good to look at the efficiency of AudioKit with very skeptical eyes and ears! I'm glad you got it sorted and you're definitely not exiled!

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

No branches or pull requests

4 participants