Using Android Studio's Profiler on a list that janks while scrolling, which build do you profile, which recording do you take, and what do you read in it?
answer
- timing needs a release-like build
- low overhead versus complete data
- frames on two threads
- threads and cores under the frames
- allocations need debuggable
basics
~20 sProfile a profileable release build with the low-overhead option and record a system trace while scrolling. Read the Display section's frame lifecycle on the main thread and RenderThread, then the Threads and CPU cores tracks under the long frames.
solid answer
~50 sDebug builds distort timing, so I profile a **profileable** release build, with `<profileable android:shell="true" />` in the manifest's `<application>` and a device on API 29 or higher, using the low-overhead profile action. I start a **system trace**, fling the list and stop. In **Display**, **Lifecycle** shows how long each frame took on the main thread and `RenderThread`, which points me at the long frames. Under them, **Threads** shows what the main thread was doing in that window, and **CPU cores** shows which thread each core was running, so I can see whether my work was competing for a core. If a long frame lines up with garbage collection, I switch to a **debuggable** build, because recording Java/Kotlin allocations or a heap dump needs one. For method-level hotspots I record a method trace, sampled or instrumented, and remember that short sampling intervals and instrumented tracing grow trace files quickly.
go deeper
Recall that the Profiler has a low-overhead and a complete-data way to launch, and that a system trace shows frames, threads and CPU on one timeline.
Explain the profileable and debuggable split: which tasks each build allows and why timing comes from the profileable release build.
Walk a long frame from Display to the main thread, RenderThread and CPU cores, and know when to switch to allocations or a method trace, and what that costs in trace size.
Decide what a team's performance evidence should be: profileable release builds as the norm, recorded traces kept for comparison, and when lab tooling replaces ad hoc profiling.
## Choose the build before the task Android Studio's **Profiler** can attach to two kinds of app process, and the choice decides what you can record and how far you can trust the timing. | | Profileable app | Debuggable app | |---|---|---| | Based on | the `release` build variant | the `debug` build variant | | Overhead | low, without the debug build's costs | carries the debug build's performance costs | | Launched with | the low-overhead profile action | the complete-data profile action | | System trace, CPU usage | yes | yes | | Java/Kotlin allocations, heap dump | no | yes | | Interaction timeline | no | yes, on API 26+ | A **profileable** app has `<profileable android:shell="true" />` in the `<application>` section of `AndroidManifest.xml`; the documentation says apps have it enabled by default, and the manifest is where you check. The recommended setup is a device on **API level 29 or higher** with Google Play, and **AGP 7.3 or higher**. For jank, timing is the evidence, so start profileable. ## Taking the recording 1. Select the release build variant (Build > Select Build Variant). 2. Use the **low-overhead** profile action for your run configuration. The app launches and the Profiler pane opens. 3. In the **Home** tab, select your app's process, usually the top one. 4. Pick the **system trace** task from Tasks. 5. Under **Start profiler task from**, choose whether to include **startup** or attach to the app as it is running. Scrolling jank does not need startup. 6. Start, fling the list several times, stop, and wait for the trace to parse. ## Reading the system trace A system trace shows system-wide activity on one timeline, so the skill is **correlating** the tracks: - **CPU Usage**: your app's share of total CPU. Highlight a stretch to filter the details to it. - **Display**: select **Lifecycle** to see how long each frame took on the **main thread** and **`RenderThread`**. This is where jank becomes visible. - **Threads**: what each thread of your app and of system processes was doing. Double-click a thread or press Enter to expand it. - **CPU cores**: what ran on each core. Hover over a block to see the thread, and you can often tell the big cores from the little ones. - **Process Memory (RSS)**: physical memory in use by the app. - **Interactions**: user input and lifecycle events. It needs a debuggable app and API 26 or higher, so it is missing from a profileable trace. Use **W/S** to zoom and **A/D** to pan. ## From a long frame to a cause 1. Find a long frame in **Display**. 2. Zoom into the **main thread** during that frame and see what work fills it: your code, layout, or something waiting. 3. Check **`RenderThread`** in the same window. A long render phase points at drawing rather than your logic. 4. Look at **CPU cores** to see whether your threads were running or other work held the cores. 5. If memory churn is suspected, rerun on a **debuggable** build and record **Java/Kotlin allocations**. Allocating faster than the collector can free memory makes the app wait and skip frames. 6. After a fix, record the same scroll again on the same build and device, and compare the two recordings rather than trusting the feel of the scroll. Because a profileable trace has no Interactions track, you line up the scroll gesture with the frames by time: start the recording, wait a moment, then fling, so the scroll is easy to find on the timeline. ## When the trace points at methods or memory - A **method trace** shows which of your functions take the time. A **sampled** trace with a short interval, or an **instrumented** trace while the app calls many methods, produces large files quickly. - The **sample interval** setting trades detail for size. The **file size limit** is ignored on Android 8.0 (API 26) and higher, but a very large trace still parses slowly and can make the IDE unresponsive. - A **heap dump** answers what is retained at one moment, which is a leak question rather than a jank question, and it also needs a debuggable build. ## Keeping the evidence Every stopped task lands in **Past Recordings** for the current IDE session. **Export** it to keep it (not every trace type exports), **import** it later or drag the file into the editor, and compare a before trace with an after trace once you have a fix.
- Why not profile the debug build you already run every day?A debuggable app comes with performance costs, so frame timing measured there overstates the problem and can point at work users never pay for. A profileable app is built from the release variant and supports the common profiling tasks without that overhead. Switch to debuggable only for what needs it: Java/Kotlin allocations, heap dumps and the Interaction timeline.
- The stutter only happens at app launch; how do you capture it?Set Start profiler task from to include startup instead of attaching to the running process. The recording then begins as the app launches, so the work done during startup is in the trace.
- Android Studio becomes unresponsive parsing your method trace; what do you change?Record less: lengthen the sample interval, shorten the recording, or prefer sampling to instrumented tracing when the app calls many methods. On API 26 and higher the file size limit is ignored, so nothing caps the trace for you.
- Profile the debug build; its timing matches what users experience.
- A profileable build can record Java/Kotlin allocations and capture heap dumps.
- A system trace shows only your app's threads, never other processes.
- A shorter sample interval always gives a better trace at no cost.
- Layout Inspector's recomposition counts already measure frame time, so no trace is needed.