Eliminating UI Lag in a High‑End Android App: Overdraw, CPU, and Scroll Optimization
After noticing persistent UI stutter on a flagship Android real‑estate app even on 6 GB devices, the author analyzes root causes—CPU overload, GPU overdraw, and memory pressure—then details step‑by‑step fixes using developer options, layout cleanup, and TraceView to achieve sub‑16 ms frame rendering.
Background
An Android engineer observed noticeable UI jitter when scrolling the home page of a real‑estate app, even on high‑end devices with 6 GB RAM, indicating that the problem was not caused by hardware limitations.
Root Cause Analysis
Three main factors were identified:
CPU saturation : Numerous background services and other apps consume CPU cycles that are needed by SurfaceFlinger to forward draw commands to the GPU.
GPU overload (overdraw) : Excessive draw commands cause frames to exceed the 16 ms budget required for smooth UI, leading to dropped frames.
Memory pressure : Although modern phones usually have sufficient RAM, the app can leak memory or hold large caches, which may cause occasional stalls.
Root‑cause analysis typically consumes about 80 % of the debugging effort, while the actual fix takes the remaining 20 %.
Detecting Overdraw
The built‑in Android developer options Debug GPU Overdraw and GPU Rendering Profile were enabled. The visual overlay showed large overdraw regions on the home page, and the rendering histogram indicated that most frames exceeded the 16 ms budget.
Overdraw Reduction Steps
The following actions were taken to eliminate unnecessary drawing operations:
Remove the activity theme background in the XML style or set it to null in onCreate.
Ensure the root ViewGroup of the activity layout does not set a background color; let child views handle their own backgrounds.
Apply the same rule to the fragment’s root layout.
Inspect each card view on the home page for redundant background attributes and remove them.
Check list items (e.g., the recommended house ListView) for unnecessary background settings.
Avoid calling notifyDataSetChanged, invalidate, or requestLayout unless required, as these force view re‑drawing.
If backgrounds overlap, override onDraw and draw everything onto a cached canvas before flushing to the screen.
CPU‑Bound Issues and TraceView Profiling
After reducing overdraw, occasional lag persisted. The Android TraceView tool was used to profile the main thread. The trace revealed that a custom MyScrollView performed heavy work during scrolling, with the onScroll callback taking about 358 ms on the UI thread.
override fun onScroll(scrollY: Int) {
LjExposureUtil.statistics(mExposureCardList, mVisibleList)
mRecommendHouseCard?.childExposure()
}Refactoring the Scroll Logic
To prevent UI blocking during active scrolling, the analytics call was moved to a method that executes only after scrolling stops.
override fun onScrollStop() {
LjExposureUtil.statistics(mExposureCardList, mVisibleList)
mRecommendHouseCard?.childExposure()
}This change removes the heavy work from the continuous scroll callbacks, resulting in smoother scrolling.
Results and Next Steps
After applying the overdraw clean‑up and scroll refactor, the GPU rendering histogram showed that the majority of frames stayed under the 16 ms threshold. Further performance gains can be achieved by replacing the current home page implementation with a RecyclerView based layout.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Beike Product & Technology
As Beike's official product and technology account, we are committed to building a platform for sharing Beike's product and technology insights, targeting internet/O2O developers and product professionals. We share high-quality original articles, tech salon events, and recruitment information weekly. Welcome to follow us.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
