Assigned
Status Update
Comments
ae...@gmail.com <ae...@gmail.com> #2
Automatic regression verification started for measurement:
ChromiumPerf/android-pixel6-perf/system_health.memory_mobile/memory:chrome:all_processes:reported_by_chrome:malloc:max_committed_size_avg/browse_news
Verification workflow id: projects/62121018386/locations/us-central1/workflows/sandwich-verification-workflow-prod/executions/f430dab5-4642-48dd-a3d6-a50904c1d68e
ChromiumPerf/android-pixel6-perf/system_health.memory_mobile/memory:chrome:all_processes:reported_by_chrome:malloc:max_committed_size_avg/browse_news
Verification workflow id: projects/62121018386/locations/us-central1/workflows/sandwich-verification-workflow-prod/executions/f430dab5-4642-48dd-a3d6-a50904c1d68e
Description
I’m using a LazyColumn (or LazyRow) with the default prefetch strategy (DefaultLazyListPrefetchStrategy from androidx.compose.foundation.lazy). When I programmatically scroll to item N (using animateScrollToItem(N)), the item N-1 is disposed. If the user quickly drags the list back to N-1, there is a flicker because that item has to be recreated from scratch. No backward prefetch occurs for N-1, and there is no mechanism to keep it in memory.
Steps to Reproduce:
1. Create a LazyColumn (or LazyRow) and enable the default prefetch strategy (DefaultLazyListPrefetchStrategy).
2. Have a sequence of items, for example, indices from 0 to 19.
3. Programmatically scroll to item N (e.g., 10) using lazyListState.animateScrollToItem(10).
4. Verify that item 9 (N-1) is disposed (check logs or other indicators).
5. As soon as the animation completes, quickly fling the list back up to item 9.
6. Observe the flicker: item 9 is briefly missing and then re-composed, because it wasn’t prefetched and had already been disposed.
Actual Behavior:
When returning to item 9, a flicker occurs because the item is re-created from scratch. DefaultLazyListPrefetchStrategy does not initiate a backward prefetch on a forward programmatic scroll, and LazyColumn disposes any items that move off-screen.
Expected Behavior:
• Item 9 would remain in memory for a short period (effectively “pinned”)
OR
• Item 9 (and possibly a few previous items) would be prefetched when scrolling programmatically to item 10, so there’s no delay or flicker on a quick return to N-1.
Additional Notes:
• DefaultLazyListPrefetchStrategy does not handle scrolling backward for programmatic calls to animateScrollToItem, and onScroll(delta, layoutInfo) is not triggered in the same way as manual scrolling.
• As soon as item 9 is off-screen, it’s disposed with no mechanism to keep it around.
• This causes flickering when the user quickly scrolls back to item 9.
Possible Solutions:
1. Extend prefetch logic (or add item pinning) to handle programmatic scrolling.
2. Provide short-term retention for items that have just scrolled off-screen (beyond-bounds layout or pinned items approach).
3. Add a way to prefetch items that might be immediately needed again when scrolling backward.