← Tue, Dec 1 digest

Finding and fixing Android memory leaks with Perfetto, SQL, and AI agents

read article ↗ hn thread ↗

Google's Android health team explains how to use Perfetto, PerfettoSQL, and AI coding agents to capture, query, and fix production memory leaks.

read it An in-depth engineering guide packed with practical SQL queries, architectural explanations, and debugging workflows for Android memory issues.

summary

Engineers from Google detail how Perfetto captures lightweight heap graphs and correlates them with kernel metrics to debug Android memory leaks. The guide covers common leak patterns like lifecycle mismatches and coroutine cancellations, provides PerfettoSQL queries for dominator tree analysis, and introduces integrations for AI coding agents. Commenters discuss the technical trade-offs of heap sampling versus tracking all allocations.

key points

  1. Perfetto's android.java_hprof records lightweight reference graphs without raw payloads, enabling production use on non-debuggable builds.
  2. PerfettoSQL allows querying heap dumps using standard SQLite syntax locally or at scale across thousands of traces with BigTrace.
  3. Open-source skills integrate Perfetto trace processors directly with AI coding agents to automate leak triage and code fixes.

who should read it

Android developers and performance engineers investigating memory consumption and leaks.

discussion positive

consensus

Commenters discuss the challenges of unified Java and native memory profiling, while a Perfetto maintainer explains how Poisson sampling balances overhead and accuracy.

pushback

One commenter expressed frustration with the article's stylistic tone, suspecting AI assistance.

best comment by lalitmaganti ↗

It samples the heap via Poisson sampling (https://perfetto.dev/docs/design-docs/heapprofd-sampling) so that large allocations are certain to be sampled and small allocations are more likely to be dropped.

If you do play around with the config directly, you can actually configure a "track all allocaitons" mode but in practice this is not super useful: either you end up slowing the device to a complete crawl or you drop lots of data as you just cannot keep up. [1]

In practice, we've found a sampling of 4096 (the default) to provide a very good tradeoff between accuracy and performance.

[1] …

A Perfetto maintainer explains the technical rationale behind Poisson heap sampling and configuration trade-offs.

Generated by an LLM from the article and thread. Check the sources before relying on it.