Close
  • Latest News
  • Artificial Intelligence
  • Video
  • Big Data and Analytics
  • Cloud
  • Networking
  • Cybersecurity
  • Applications
  • IT Management
  • Storage
  • Sponsored
  • Mobile
  • Small Business
  • Development
  • Database
  • Servers
  • Android
  • Apple
  • Innovation
  • Blogs
  • PC Hardware
  • Reviews
  • Search Engines
  • Virtualization
Read Down
Sign in
Close
Welcome!Log into your account
Forgot your password?
Read Down
Password recovery
Recover your password
Close
Search
Logo
Logo
  • Latest News
  • Artificial Intelligence
  • Video
  • Big Data and Analytics
  • Cloud
  • Networking
  • Cybersecurity
  • Applications
  • IT Management
  • Storage
  • Sponsored
  • Mobile
  • Small Business
  • Development
  • Database
  • Servers
  • Android
  • Apple
  • Innovation
  • Blogs
  • PC Hardware
  • Reviews
  • Search Engines
  • Virtualization
More
    Home Latest News
    • Mobile

    How Facebook Cut Down the Crashes in Its iOS App

    Written by

    Darryl K. Taft
    Published August 26, 2015
    Share
    Facebook
    Twitter
    Linkedin

      eWEEK content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

      The engineering team at Facebook is constantly tuning its systems and apps to run more smoothly and better suit users, particularly those on mobile devices.

      To that end the Facebook team set out to reduce the number of crashes in the Facebook iOS app to increase its reliability.

      “In the past, most of the crashes have been due to programmatic errors, and they always came with a stack trace that blamed the line in the code that caused the crash and always offered a hint as to what the issue might be,” said a post on the Facebook engineering blog written by Ali Ansari and Grzegorz Pstrucha, two engineers at Facebook.

      According to the post, Facebook witnessed a drop in its measured crash rate but also noticed from App Store reviews that the community was still frustrated with the app crashing.

      “We dug into the user reports and began to theorize that out-of-memory events (OOMs) might be happening,” the post said. “OOMs occur when the system runs low on memory and the OS kills the app to reclaim memory. It can happen whether the app is in the foreground or the background. We refer to these internally as FOOMs and BOOMs, respectively — it’s just a bit more fun to say that the app went BOOM!”

      Facebook eventually fixed the problem with a combination of internal tooling, migration to the newest iOS technologies and some additional cleverness that helped the company accurately measure crash and reliability problems in the first place.

      To get a handle on how often their app was being terminated due to OOM crashes, Facebook started counting all the known paths through which the application could be terminated and then logging them, the blog said. The question the team looked into was “What can cause the application to start up?” The company came up with six reasons why an app could need to start up:

      * The app was upgraded.

      * The app called exit or abort.

      * The app crashed.

      * A user swiped up to force-exit the application.

      * The device restarted (which includes an OS upgrade).

      * The app ran out of memory (an OOM) in the background or the foreground.

      “By process of elimination, looking for instances that didn’t fall into the other cases, we could then figure out when an OOM had occurred,” the post said. “We also kept track of when the app backgrounded and foregrounded so that we could accurately break down OOMs into BOOMs and FOOMs, respectively.”

      The logging showed that there was a higher rate of OOMs on devices with less memory, “which was expected and reassuring since the application process was more likely to be evicted on a constrained-memory device,” the post said.

      The team’s first effort to reduce the number of OOMs was to attempt to shrink the memory footprint of the app by proactively de-allocating memory as quickly as they could, as soon as it was no longer needed.

      Fixing the leaks led to some reduction in the OOM crash rate, but not the significant reduction the team was hoping for. So, “Next, we dived into the memory profiler in Apple’s Instruments application and noticed a repeated pattern of UIWebView allocating a lot of memory once the application opened any Web page. We also found that the memory was often not reclaimed, even after the user navigated away from the page and the web view was closed.”

      How Facebook Cut Down the Crashes in Its iOS App

      Thus the team tried a number of optimizations, such as cleaning up the cache and clearing the content, but the memory footprint of the app’s process was always significantly increased after navigating to a Web view, the team said.

      However, iOS 8 introduced a new class — WKWebView — that performs most of its work in a separate process, which means that most Web-view-related memory usage would not be attributed to the Facebook app’s process. In a low-memory event, the Web view’s process could be killed and their app would be more likely to stay alive, the post said. “After we migrated our app to WKWebView, we did indeed see a significant reduction of OOMs in our app,” the engineers said in the post.

      Yet, even after migrating to WKWebView, the team still found that a small memory leak could affect the OOM rate significantly, especially on the more memory-constrained devices. With the company’s frequent release schedule and many teams contributing to the app, Facebook knew it was important to both catch and prevent memory leaks in the apps they release. So the company used its CT-Scan infrastructure — originally designed to test for mobile performance — to log the amount of resident memory in the process, allowing CT-Scan to flag regressions as soon as they were introduced. This has helped to keep the OOM rate much lower than when the team first started working on it.

      However, the last key tactic the team used was to construct an in-app memory profiler, to allow profiling the app quickly by tracking all Objective-C object allocations. The team configured this in CT-Scan and in the internal builds of their app.

      “Here’s how it works: For each class in the system, it keeps a running count of how many instances are currently alive,” the post said. “We can query it at any point and log the current number of objects for each class. We can then analyze this data for any abnormalities release-to-release to identify changes in the overall allocation patterns of our app, usually helping identify leaks when any count shifts drastically. We managed to implement this in a way that is performant enough that it doesn’t produce any noticeable impact in application performance to the user.”

      After the company rolled out the changes to resolve memory issues in the Facebook iOS app, the team saw a significant decrease in (F)OOMs and in the number of user reports of the app crashing.

      “OOM crashes were a blind spot for us because there is no formal system or API for observing the events and their frequency,” the post said. “No one likes it when an app suddenly closes.”

      Darryl K. Taft
      Darryl K. Taft
      Darryl K. Taft covers the development tools and developer-related issues beat from his office in Baltimore. He has more than 10 years of experience in the business and is always looking for the next scoop. Taft is a member of the Association for Computing Machinery (ACM) and was named 'one of the most active middleware reporters in the world' by The Middleware Co. He also has his own card in the 'Who's Who in Enterprise Java' deck.

      Get the Free Newsletter!

      Subscribe to Daily Tech Insider for top news, trends & analysis

      Get the Free Newsletter!

      Subscribe to Daily Tech Insider for top news, trends & analysis

      MOST POPULAR ARTICLES

      Artificial Intelligence

      9 Best AI 3D Generators You Need...

      Sam Rinko - June 25, 2024 0
      AI 3D Generators are powerful tools for many different industries. Discover the best AI 3D Generators, and learn which is best for your specific use case.
      Read more
      Cloud

      RingCentral Expands Its Collaboration Platform

      Zeus Kerravala - November 22, 2023 0
      RingCentral adds AI-enabled contact center and hybrid event products to its suite of collaboration services.
      Read more
      Artificial Intelligence

      8 Best AI Data Analytics Software &...

      Aminu Abdullahi - January 18, 2024 0
      Learn the top AI data analytics software to use. Compare AI data analytics solutions & features to make the best choice for your business.
      Read more
      Latest News

      Zeus Kerravala on Networking: Multicloud, 5G, and...

      James Maguire - December 16, 2022 0
      I spoke with Zeus Kerravala, industry analyst at ZK Research, about the rapid changes in enterprise networking, as tech advances and digital transformation prompt...
      Read more
      Video

      Datadog President Amit Agarwal on Trends in...

      James Maguire - November 11, 2022 0
      I spoke with Amit Agarwal, President of Datadog, about infrastructure observability, from current trends to key challenges to the future of this rapidly growing...
      Read more
      Logo

      eWeek has the latest technology news and analysis, buying guides, and product reviews for IT professionals and technology buyers. The site’s focus is on innovative solutions and covering in-depth technical content. eWeek stays on the cutting edge of technology news and IT trends through interviews and expert analysis. Gain insight from top innovators and thought leaders in the fields of IT, business, enterprise software, startups, and more.

      Facebook
      Linkedin
      RSS
      Twitter
      Youtube

      Advertisers

      Advertise with TechnologyAdvice on eWeek and our other IT-focused platforms.

      Advertise with Us

      Menu

      • About eWeek
      • Subscribe to our Newsletter
      • Latest News

      Our Brands

      • Privacy Policy
      • Terms
      • About
      • Contact
      • Advertise
      • Sitemap
      • California – Do Not Sell My Information

      Property of TechnologyAdvice.
      © 2024 TechnologyAdvice. All Rights Reserved

      Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.

      ×