Mosmoxmosmox

Mosmox journal

In focus — mobile performance.

A selection of publications grouped under the mobile performance tag.

How to Reduce Battery Consumption in a Mobile App

How to Reduce Battery Consumption in a Mobile App

Users judge an app not only by its features but by how much of the device it consumes. Excessive location use, background requests, frequent syncs and heavy animations shorten battery life and erode trust. And when the system lists an app near the top of battery consumers, the decision to uninstall comes quickly.

Energy use is hard to notice during development: the phone on the desk is plugged in and sessions are short. That is why in our projects we measure it deliberately, with a defined scenario and on real devices. Below is where costs usually hide, what thresholds Google Play sets and how to build a process so energy efficiency does not depend on random complaints.

Why this is now a Google Play visibility issue

Android vitals lists excessive partial wake locks among its core quality metrics, alongside crash rate and ANR. Partial wake lock use is considered excessive when all of an app's partial wake locks together run for two or more hours in a 24-hour period, counting only time in the background or while a foreground service is running. If this happens in more than 5% of sessions over 28 days, Google Play may reduce the app's visibility.

Vitals exempts some scenarios where the user benefit is clear and there is no alternative: audio playback, location and user-initiated JobScheduler jobs. All other background activity needs a justification.

Android vitals metricWhat it measuresTypical cause
Excessive partial wake locksTotal background wake lock time of 2+ hours per dayA forgotten release, custom background logic instead of WorkManager
Stuck partial wake locksA single wake lock held for a long timeAn exception-handling bug, a wake lock with no timeout
Excessive wakeupsFrequent device wakeups from alarmsExact AlarmManager alarms for tasks that do not need precision
Excessive background Wi-Fi scansNetwork scanning in the backgroundDevice discovery or location lookups without need
Excessive background network usageMobile data used in the backgroundServer polling, unbounded prefetching

Where to look for costs

  • Background work without a clear need. Syncing every few minutes when data changes once a day.
  • Polling instead of events. Push messages or batched sync are almost always cheaper than regular polling.
  • Sensors left active. GPS, camera or Bluetooth scanning after the screen is closed.
  • Wrong location accuracy. High accuracy where city- or district-level would do.
  • Off-screen animations and video. A Lottie animation or autoplay in a hidden tab keeps loading the GPU.
  • Third-party SDKs. Analytics and ads may run their own background jobs the team does not know about; we described how to audit dependencies in our article on unnecessary third-party libraries.

How to measure energy use

  1. Record a baseline scenario. Device model, OS version, network type, brightness, usage duration and background conditions. Without this, two measurements cannot be compared.
  2. Choose tools. On Android, the Power Profiler in Android Studio on devices that support energy measurement, Background Task Inspector for WorkManager and Perfetto system traces. On iOS, the Energy Organizer and energy reports in Xcode, plus MetricKit for production data.
  3. Profile a concrete journey. For example, 30 minutes of navigation, an hour in the background after an order or an overnight idle period. A generic "one-day test" yields little useful information.
  4. Check background mode separately. Lock the screen and see what the app does over the next few hours: wake locks, network requests, alarms.
  5. Confirm the optimisation did not break freshness. Less frequent sync must not lead to stale statuses in key journeys.
  6. Compare releases with the same method. An energy budget is only useful when it is checked regularly.

What usually has the biggest effect

  • Moving background work to WorkManager with network and battery constraints; the minimum interval for a periodic job there is 15 minutes, which is enough for most scenarios.
  • Replacing polling with push messages that wake the app only when there is new data.
  • Batching network requests so the radio switches to its active state less often.
  • Choosing the minimum sufficient location accuracy and turning it off when the result is not visible to the user.
  • Stopping animations, video and sensors in lifecycle callbacks when the screen is inactive.
  • Local caching that reduces repeated downloads; its limits are covered in our article on caching.

On iOS the system restricts background work more strictly, but that does not take responsibility away from the team. For tracking movement that does not need high accuracy, the significant-change location service is a better fit than continuous GPS. The system runs background refresh via BGTaskScheduler at its own discretion, so critical logic should not depend on it. And in Low Power Mode, which an app can detect through ProcessInfo, it makes sense to automatically reduce update frequency and turn off video autoplay and decorative animations.

Transparency for users

People should understand why a permission or background activity is needed. Navigation during a trip is obvious. An app reading location with no visible outcome looks like a risk to both privacy and battery. Explain the purpose before the system prompt, offer a choice of update frequency and show when background work is active, for example with an ongoing notification while tracking a delivery.

Common mistakes

  • A wake lock with no timeout that is never released after an exception.
  • Exact alarms for tasks that do not need minute-level precision.
  • Using a foreground service to "work around" background restrictions.
  • Testing only while charging and on stable Wi-Fi.
  • No post-release monitoring: problems are found through reviews rather than metrics.

Energy efficiency checklist

  • Every background task has an owner, a justification and constraints.
  • No wake locks without timeouts; wake lock and wakeup vitals are below thresholds.
  • Polling has been replaced with push or batched sync.
  • Location accuracy matches the task, and sensors turn off when the screen is not active.
  • The energy scenario is checked on real devices before every major release.
  • Users can see why background activity is needed and can control it.

Sources: Android Developers: Android vitals; Android Developers: Excessive partial wake locks; Android Developers: WorkManager; Android Developers: App quality and user experience; Apple: MetricKit.

Caching in Mobile Apps: Where It Helps and Where It Creates Problems

Caching in Mobile Apps: Where It Helps and Where It Creates Problems

Caching reduces waiting and the number of network requests, but stale data can destroy trust. A user will wait half a second to see an up-to-date order status, and is far less willing to act on wrong information: paying for an item that is already out of stock, or driving to an address that has changed.

In our projects a cache is almost never "just an optimisation". It is part of the data architecture that determines what people see without a network, how fast a screen opens, and whether data from two accounts gets mixed up on one phone. Below is how we decide what to cache, how to choose a freshness window and which mistakes occur most often.

What to cache and what not to

  • data that changes rarely: reference lists, categories, interface settings;
  • the last successful state for offline reading: the feed, order history, profile;
  • images and assets with a controlled lifetime;
  • drafts and local progress that must not be lost;
  • results of expensive on-device computations.

Be careful with balances, prices, stock levels, payment statuses and anything people use to make financial decisions. Such data can be shown from a saved copy only with a clear timestamp and a mandatory server check before any action. Access tokens and other secrets should not live in a regular cache at all; Keychain and Android Keystore exist for that, as we explained in our article on storing secrets.

A policy for each data type

For every data type, define three things: the source of truth, the freshness window and the behaviour after an error. An account balance, an article list and a user avatar should not share one caching rule. Below is an example of the table we draft at the start of a project; the specific values depend on the product and are our working guidelines rather than a standard.

Data typeStrategyIndicative freshness windowBehaviour offline
Avatars, coversDisk image cacheDays, refreshed when the URL changesShow the saved copy
Feed, catalogueStale-while-revalidateMinutesShow the saved copy with a timestamp
Profile, settingsLocal database as the UI sourceUntil the next syncShow it and allow editing a draft
Price, stock, balanceNetwork first, cache for display onlySecondsShow with a warning, block the action
Payment statusNo cached decisionsAlways from the serverSay the status is unknown

How to build a cache in an app

Android's data layer guidance emphasises clear data sources and repositories that hide the details of data retrieval from the UI. In practice, local storage should not be an accidental optimisation nobody controls. We apply the same principle on iOS; see our article on MVVM and Clean architecture for details.

  1. Define cache layers. Memory for the current session, disk or a database (Room, SQLite, Core Data, SwiftData) for data across launches, and an HTTP cache for server responses.
  2. Use HTTP features. Cache-Control, ETag and conditional requests let you receive a 304 response instead of the full body when data has not changed. OkHttp and URLCache support this without extra code.
  3. Make the repository the single access point. The UI subscribes to data from the repository, which decides when to show the cache and when to go to the network.
  4. Add a schema version. After an app update, the old cache must either migrate or be cleared safely.
  5. Tie the cache to the account. Keys should include the user identifier, and signing out should clear personal data.
  6. Limit size. An unbounded disk image cache eventually takes hundreds of megabytes and hurts how the app is perceived.
  7. Show the state to the user. An "updated 5 min ago" label and pull-to-refresh remove most questions about stale data.

Agree on caching headers with the backend at the API design stage: if the server does not return an ETag or a correct Cache-Control header, the client has to invent its own rules. We covered this in our article on designing an API for a mobile client.

How to show saved data in the interface

Most often the problem is not the cache itself but an interface that does not distinguish between states. The same screen can show fresh data, a saved copy, a partially refreshed list or a refresh error on top of old data. If all these states look identical, people cannot understand why the price in the cart differs from the price in the catalogue.

  • Fresh data needs no label at all.
  • A saved copy gets an unobtrusive caption with the time of the last update.
  • A refresh in progress is shown with a thin indicator, without blocking the content already on screen.
  • A refresh error does not wipe the old data: it is better to keep it and show a short message with a retry button.

Critical actions such as payment or booking follow a separate rule: before confirmation, the app always checks current data on the server, even if the cached data looks fresh.

Cache and memory: the Zomato lesson

Caching affects stability, not only the network. In the Zomato case study published on Android Developers, the team reworked its caching mechanism among other steps and achieved a 60% drop in out-of-memory issues. It is a good reminder that an unbounded in-memory cache is one of the typical causes of crashes on budget devices.

Common mistakes

  • Cache without invalidation. Data is written once and never refreshed.
  • Mixed accounts. After switching users, the previous user's orders appear on screen.
  • No schema version. An app update reads the old format and crashes.
  • Invisible stale state. People see a saved copy but do not know it.
  • Caching errors. An error response or an empty list is stored as a valid result.
  • Unbounded growth. The cache takes more space than the app itself.

Cache verification checklist

Caching works when it hides latency but not the truth. Before a release we go through these scenarios:

  • Sign out and sign in as another user: no foreign data.
  • Change data from another device: the app refreshes it within the defined window.
  • Switch networks during loading: no empty screens or duplicates.
  • Update the app with an old cache version: migration or a clean reset.
  • Work offline: a clear timestamp and an available refresh action.
  • Long-term use: cache size stays within the set limit.

Sources: Android Developers: Data layer architecture; Android Developers: Build an offline-first app; MDN: HTTP caching; Android Developers: Zomato app speed case study.

Lyft: Why Fast Android Startup Matters for Drivers

Lyft: Why Fast Android Startup Matters for Drivers

In a service app, a delay is more than an inconvenience. For a driver waiting for a request or plotting a route, slow startup can mean a missed opportunity, a late arrival or lost income. Here, speed is part of the work tool, not a "nice bonus".

The Lyft case described on Android Developers is interesting not only for its result but also for how the team convinced leadership to invest in performance at a company where every project competes for resources. We break down what exactly they did, what numbers they got, and how we apply this approach when justifying performance work for our own products.

The Lyft case: how the task came about

Lyft is a ridesharing service used every day by millions of drivers and riders. The team kept an eye on performance and noticed that the Lyft Driver app on Android started slowly. But developers' impressions aren't an argument for leadership, so the first step was to show the scale of the problem.

Android vitals in Google Play Console helped here. A comparison with ten other apps in the category showed that Lyft Driver's startup time was 15–20% worse. The team then estimated the cost: one developer working for one month could make a significant improvement. The combination of "a clearly measured problem and a bounded investment" made the decision obvious for leadership.

Four startup phases and where the bottleneck was

The team chose time to interact as its main metric — that is, time to full display (TTFD), not just the first frame. Startup was broken down into four phases.

PhaseWhat happensAnalysis result
1. Process startthe system creates the app processno issues
2. ActivityUI rendering kicks offno issues
3. Bootstrapnetwork requests for the data the home screen needsthe bottleneck
4. Displaythe driver interface openswaits for bootstrap to finish

Profiling showed that time was lost in the third phase: the app waited on network responses before showing the working screen. The fixes were relatively simple:

  • after decomposing backend services, some network calls were removed from the critical launch path entirely;
  • calls that could run asynchronously were made asynchronous;
  • data needed later rather than at launch stopped blocking startup;
  • blocking calls were moved to the background;
  • data started being cached between sessions.

Note that there are no "magic" compiler optimisations here. The main gain came from reviewing what the first screen really needs. In our experience, network bootstrap is the most common cause of slow TTFD in service and e-commerce apps.

The result: from milliseconds to sessions

The changes delivered an average 21% reduction in startup time and a 5% increase in driver sessions. The second number matters more than the first: it translates a technical improvement into business language. Seeing the result, Lyft leadership expanded the app excellence initiative and took on other areas, including stability.

An important caveat: 5% more sessions is the result for a specific product with a specific audience. It can't be mechanically transferred to another app. But the logic — tying speed to the user's key action — is always worth transferring.

Why context matters more than the average

What you should measure is not an abstract startup but a critical business scenario. In a driver app that might be going online, accepting a ride, the map or confirming completion. For a store — the catalogue and cart; for a bank — the balance and a transfer.

  • Define the moment after which the user can actually work, and mark it with reportFullyDrawn(), as Lyft did with time to interact.
  • Measure cold, warm and hot starts separately. A driver switching between a navigation app and yours experiences mostly warm and hot starts.
  • Segment data by device class and network conditions. The average hides drivers on old phones and in areas with weak coverage.
  • Check that optimisation doesn't hurt stability. Caching and asynchrony add new states that need testing.

How to build a business case for performance

  1. Gather a market comparison. Android vitals shows startup time against a peer group; Xcode Organizer shows trends by version on iOS.
  2. Pick one product metric that speed can influence: sessions, conversion to the key action, day-one retention.
  3. Scope the investment tightly: "one developer, four weeks" is more convincing than "a big optimisation".
  4. Break startup into phases and find the one that takes the most time.
  5. Start with the simplest changes: remove unnecessary requests, cache, defer what isn't important.
  6. Ship changes as a controlled release and compare the technical and product metrics against a control group.
  7. Show the result to leadership and propose the next step — as the Lyft team did.

We covered the more engineering-heavy side — what to do once network bootstrap is optimised but startup is still slow — using the examples of Gmail Wear OS and Android Calendar with Baseline Profiles.

Typical mistakes

  • Optimising TTID while the user is actually waiting for network data after the first frame.
  • Sequential requests at startup, each waiting for the previous one.
  • No cache between sessions: the app starts from an empty screen every time.
  • Justifying performance work with impressions rather than a market comparison and a product metric.
  • Prioritising the performance backlog separately from product and operations teams.
  • Not checking whether cached data has become so stale that it misleads the user.

Action plan

  1. Define the key action users open the app for, and mark the moment the app is ready for it.
  2. Compare your startup time with peers in Android vitals.
  3. Break startup into phases and measure each.
  4. Remove from the critical path every network request the first screen can do without.
  5. Add caching between sessions with honest indication of data freshness.
  6. Ship changes in a controlled release and compare technical and product metrics.
  7. Add the startup metric to the product team's regular report.

Speed becomes a business advantage when it supports a user's specific job. That's why the performance backlog must be prioritised together with product and operations teams. You'll find the general framework of startup metrics in our article on app startup speed.

Sources: Android Developers: Lyft improves Android app startup time; Android Developers Blog: How a single Android developer improved Lyft's Drivers app startup time by 21% in one month; Android Developers: App startup time; Android vitals: App startup time.

Journal

Ideas and products