iOS App Performance Tips

Mohit Bhalla
3 min readSep 18, 2017

Hi guys, Today I am going specify some key points which we must take into consideration while iOS app development.

From this post onwards I will be considering all aspects i.e WWH i.e What , Why and How.

What : How can we improve performance of app.

Why: Power usage and memory consumption are extremely important considerations for iOS apps, and there are many other considerations as well. If app is not tunned properly it will affect UX aspect of app.

How: So lets begin…..

Extensive Power consumption on mobile devices is always an issue. The power management system in iOS conserves power by shutting down any hardware features that are not currently being used. You can help improve battery life by optimizing your use of the following features:

  • The CPU
  • Wi-Fi, Bluetooth, and baseband (EDGE, 3G) radios
  • The Core Location framework
  • The accelerometers
  • The disk

Let me discuss the optimizing work in modules for ease

APP TUNNING:

APP TUNNING means to improve performance of app in term on CPU , memory and resource usage. Below are some key points which we must take into consideration while developing iOS app.

  • App launch time must be decreased: First impression of app is the app start time so App launch time must be decreased by deferring and decreasing the number of task that or not needed initially.
  • Load subsystem when needed: Load side menu or any other menu then main screen, and then start loading user interactions and perform action on event.
  • Load View efficiently: AwakeFromNib should only contains UI initialisation code only. We should initialize other component as and when required.
  • Avoid global initialisations: We should avoid intializing variable at global level because The system initializes global variables before calling your app’s main routine.
  • Leave the idleTimerDisabled property of the shared UIApplication object set to NO whenever possible. The idle timer turns off the device’s screen after a specified period of inactivity. If your app does not need the screen to stay on, let the system turn it off. If your app experiences side effects as a result of the screen being turned off, you should modify your code to eliminate the side effects rather than disable the idle timer unnecessarily
  • Load resources lazily, if possible : You should never load a resource file until it is actually needed. Prefetching resource files may seem like a way to save time, but this practice actually slows down your app right away. In addition, if you end up not using the resource, loading it wastes memory for no good purpose.
  • Coalesce work: It generally takes less power to perform a set of calculations all at once than it does to perform them in small chunks over an extended period of time. Doing small bits of work periodically requires waking up the CPU more often and getting it into a state where it can perform your tasks.

NETWORK TUNNING:

  • Do not POLL : Connect to external network servers only when needed, and do not poll those servers. Avoid doing work that requires polling. Polling prevents the CPU from going to sleep. Instead of polling, use the NSRunLoop or NSTimer classes to schedule work as needed.
  • Transmit small data: Minimizing the amount of data sent and received prolongs battery life, and may reduce the cost for users on metered Internet connections that bill by the megabyte. If your app performs downloads of potentially large files, you should also provide a way to pause those downloads and resume them later.
  • Prefrer Wi-fi connectivity : Connect to the network using the Wi-Fi radios whenever possible. Wi-Fi uses less power and is preferred over cellular radios.

STORAGE TUNNING:

  • Write only the portions of the file that changed. Avoid writing out the entire file just to change a few bytes
  • Use Core Data or SQLite for large data sets : Instead of Flat file use Core data or Sqlite because they are faster and reliable.
  • Minimize file access at app start.
  • Make resource files as small as possible : Compress PNG images — the preferred image format for iOS apps — example use the pngcrush tool .

Operation to be performed on Main thread:

  1. Update UI
  2. Touch handling
  3. Never perform network operation on main thread.

Background thread:

  1. Network call
  2. Some logical functionality.
  3. Network response Parsing
  4. Any Unbound task
  5. File access.
  6. Database access

Happy coding and keep sharing :)

Other Post:

Swift 4 updates

--

--

Mohit Bhalla

Principle Engineer iOS, Wynk, Airtel | ex Hindustan times