BT

InfoQ Homepage News How Reddit Rewrote Their iOS App to Improve Performance, Modularity, and Testing

How Reddit Rewrote Their iOS App to Improve Performance, Modularity, and Testing

This item in japanese

Bookmarks

Reddit has been hard at work in the last year to improve the performance of their iOS app while also making it suitable for faster iteration cycles, improved test coverage, and better extensibility. All of this was made possible by evolving the app original MVC architecture into a Model-View-Presenter (MVP) architecture.

One of the major issues with the original MVC design is its proneness to massive view controllers, due to the tight coupling between the view and the controller that it favours. Among the effects of this was a noticeable degradation of scroll performance from 60fps to 45–55 fps, writes Reddit engineer Andrew Rohn. Any attempt to improve the view implementation required duplicating thousands of controller lines of code due to the view-controller coupling. So, Reddit engineers set out to rewrite parts of their app and move to a Model-View-Presenter (MVP) design.

While not too different from MVC, MVP enables a better separation of presentation and business logic, as the following picture shows.

Following this idea, Reddit engineers removed any non-view logic from the UIViewController and moved it to a Presenter class solely responsible for the view-model interaction. Thus the UIViewController can take on responsibilities such as dealing with user input, setting up the view, bindings, and managing the view lifecycle. The Presenter concerns itself with data fetching and transformation, and the presentation. A key point of MVP is that the Presenter has no direct access to the view object and accesses it through an interface.

Moving to MVP improved the modularity and reusability of the code and made the business logic testable in isolation from the view. Among other benefits of MVP in comparison with MVC, Rohn highlights its better suitability for composition over inheritance, since the Presenter is a component separated from the view controller and can be more easily reused or swapped with a different implementation. Most importantly, MVP enabled the rewrite of the view layer implementation to solve the scroll performance issue by going multithreaded with Texture. The major hurdle using Texture, explains Rohn, was dealing with state access synchronization, which required locking the state while the Presenter is busy rendering the feed UI.

MVP is just one option to move beyond MVC among many. If you are interested in a comparative analysis of a number of alternative approaches to iOS app architecture, do not miss the book App Architecture, iOS Application Design Patterns in Swift by Chris Eidhof, Matt Gallagher, and Florian Kugler.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.