Apple Interview Question: If you have a program that ru... | Glassdoor

Interview Question

Ios Software Engineer Interview Cupertino, CA

If you have a program that runs slow, how will you improve

  it to run faster?

Interview Answer

7 Answers


I suggested to check how memory was allocated (if it leaked some) and what operations consumed more CPU cycles and perform some operations in a background thread, keeping the UI update in the main one in order to give UI responsiveness.

Interview Candidate on Sep 19, 2011

It depends on the application. Is it CPU-bound or I/O-bound?
1. Check all I/O that the application does: look at I/O speeds, blocking vs. non-blocking calls, see how much time CPU is waiting on I/O using iostat.
2. If I/O is ok, look at CPU usage. Profile the application: look at function call timings, see if any function call is taking abnormally long. Look at garbage collection that may be more frequent if program is using a lot of memory, perhaps due to a memory leak.

TI on Apr 10, 2012

Calculate the comlpexity and findout what unit of code taking too much time.
Make the strategy and improve the code complexity on that.
If you are done with that. Go over memory management and find the way to improve it.

Also try to make multithreading or pre data process management steps if needed.

DK on Oct 30, 2012

First thing to approach this problem will be to perform code optimization.
There are five steps in which this can be done to increase overall efficiency of the program.
1. Compile time evaluation.
2. Elimination of sub expressions.
3. Dead code elimination
4. Frequency reductions
5. Strength reductions.

If you have done all the above steps and still the performance has not improved as expected, then you can see the memory usage
1. look for memory leaks by performing an operation in the application and record memory usage and memory free after operation is done, so that you will be one step closer to the offending operations.
2. Check if launching the applications causes huge amount of memory to be allocated from heap, that will cause the OS to run slower, since it will try and allocate resources by taking resources from other applications which will cause other applications to ask for resources, so the system at this point will be in loop which could be one of the reasons why the system is slow.

Vishal Mandekar on Apr 7, 2013


I've always heard the first rule of performance optimization is don't - until you're absolutely sure what needs to change. Randomly changing code/guessing is a great way to waste time and possibly make things worse, or not find any gains.

Profile, analyze, figure out where the time is spent before touching any code!

TI's response is the best one I think.

m on Feb 27, 2014

I don't know

Anonymous on Dec 1, 2015

Couple of things to double check:
- removing Unreferenced or dead code from executable file. This can be done some using Xcode settings.
- eliminate memory leaks: can be checked using instruments.
- use SQLite or codedata instead of manipulating data from flat files.
- use Xcode compiler level optimization’s for the final release build.
- don’t block the main thread, instead use GCD to run potential big operations in background thread.
- minimize global variables, instead use run time Malloc allocated block of memory.

Anonymous on Mar 14, 2018

Add Answers or Comments

To comment on this, Sign In or Sign Up.