Instruments Xcode speed up an iOS app

Hi.


When I build iOS app from Xcode as usually, piece of code sent to global queue works slow, it makes calculations 7 sec.

When I launch Instruments and press record, app builds from there and that calculations are being completed just in 0.4 sec!

Overall, that's just a method that compares 2 different structs but many times. Working in a loop maybe hundreds of thousands times. Nothing with UI, only flat calculations.


I can unplug iPhone after that (when built from Instruments), restart an app and builded from Instruments app calculates most expensive thing still incredibly fast, 0.4 seconds!

Once I build an app from Xcode it calculates that thing very slow again, 7 seconds.


Am I crazy? How could it be?

As I understand now, that piece of code can naturaly be calculated very fast in 0.4 seconds. But why when I am building app from Xcode, it is so slow, 20 times slower?!

Answered by OOPer in 335597022

Have you selected Product > Profile to run your code under Instruments?


If so, it may be a problem of Optimization.


Try changing the Build Configuration.

- Open a scheme menu by pressing Scheme pull-down at the right of Stop button.

- Choose Edit Scheme...

- Select Run in the left side pane

- Change the Build Configuration pull-down from Debug to Release

- Close

- Choose Product > Clean Build Folder

- And then Build and Run your project again


This enables Swift compiler to use -O setting, which may improve some operations more than hundred times faster, in some cases.


The default Build Configuration for Profile is set to Release, the defualt for Run is Debug. So, Profile may run your code faster.


Please try.

Accepted Answer

Have you selected Product > Profile to run your code under Instruments?


If so, it may be a problem of Optimization.


Try changing the Build Configuration.

- Open a scheme menu by pressing Scheme pull-down at the right of Stop button.

- Choose Edit Scheme...

- Select Run in the left side pane

- Change the Build Configuration pull-down from Debug to Release

- Close

- Choose Product > Clean Build Folder

- And then Build and Run your project again


This enables Swift compiler to use -O setting, which may improve some operations more than hundred times faster, in some cases.


The default Build Configuration for Profile is set to Release, the defualt for Run is Debug. So, Profile may run your code faster.


Please try.

Wow, thank you so much! It's really works! Calculations are incredibly fast now:)


PS: Yes, I have selected Product > Profile to run code under Instruments.


Can you tell me what functionality I will lose when setting up Build Configuration to release?

Thank you!

Can you tell me what functionality I will lose when setting up Build Configuration to release?


Good question.

- In the Release configuration, Source Code debugging may not work. You may need to watch some assembly screen while debugging

- Step-into or Step-over may not work as expected

- You cannot watch some variables, as Optimization may blow away...

- Some debugging functions, for example `assert`, shows different behavior than in Debug configuration

- And some other things related to debugging


So, you should better use Release configuration only when you have enough debugged your app.

Instruments Xcode speed up an iOS app
 
 
Q