Move up the Stack

April 22, 2016

It’s Always Nice to Get to Use Someone Else’s Solution to a Problem.

As the amount of data displayed in our current app has grown, the number of API calls to full refresh the data on the dashboard has gone up, and there’s dependancies between certain calls, branching based on account features enabled, and so on.

The original system was a handful of nested completion blocks, then when that turned into a pyramid of doom we initialized refactored with dispatch groups and the code was more readable, and everything was great for a while.

We hit a hard to reproduce bug related to the login system last sprint, so in in the process of nailing down the behavior and making sure that all of the work in the queue was cancelled before signing out the I ended up rewriting the code to use NSOperation and NSOperationQueue and using dependancies between operations.

Building the entire graph of operations and letting the operation queue deal with dependancies ended up speeding up login significantly, and it didn’t directly solve the bug, it helped expose the code that was causing the issue. It was a great reminder that for many things, there’s a decent value in moving up the stack rather than trying to use the low level tools to solve the problem yourself.