$npx -y skills add skydoves/compose-performance-skills --skill configuring-lazy-prefetchUse this skill to tune Jetpack Compose lazy-layout prefetch with LazyLayoutCacheWindow (Compose Foundation 1.9+, @ExperimentalFoundationApi) and pausable composition in prefetch (Compose Foundation 1.10+, default on). Covers configurable Dp-based ahead/behind cache windows plumbe
| 1 | # Configuring Lazy Prefetch — Cache Window and Pausable Composition |
| 2 | |
| 3 | Lazy layouts pre-compose items just outside the viewport so they're ready when the user scrolls. Compose Foundation 1.9 added `LazyLayoutCacheWindow` for configurable ahead/behind extents. Compose Foundation 1.10 made prefetch composition pausable by default — work spreads across multiple frames instead of one. Most apps still rely on legacy single-frame prefetch and unknowingly pay for it during heavy scrolling. This skill teaches Claude when (and only when) to widen the window or implement nested prefetch, and how to validate the change with Macrobenchmark. |
| 4 | |
| 5 | ## When to use this skill |
| 6 | |
| 7 | - Macrobenchmark `FrameTimingMetric` shows dropped frames at high scroll velocity even though item composables are skippable. |
| 8 | - Items are content-heavy: large images, decoded videos, nested grids, or expensive measurement work. |
| 9 | - The developer wants composition retained for items the user scrolled past briefly (e.g. flick-back gesture). |
| 10 | - An outer lazy layout contains items with their own inner lazy layouts (e.g. `LazyColumn` rows that each host a `HorizontalPager` or inner `LazyRow`). |
| 11 | - The developer mentions `LazyLayoutCacheWindow`, `NestedPrefetchScope`, "prefetch window", "ahead extent", or "pausable composition for prefetch". |
| 12 | |
| 13 | ## When NOT to use this skill |
| 14 | |
| 15 | - Items are cheap and short; default behavior is sufficient — do not pre-emptively configure a window. |
| 16 | - Item composables are non-skippable / unstable; widening the window only spreads the same waste over more frames. First fix `../optimizing-lazy-layouts/SKILL.md` and the underlying stability via `../../stability/diagnosing-compose-stability/SKILL.md`. |
| 17 | - The bottleneck is per-item layout or draw rather than composition. Use Android Studio Profiler / Layout Inspector to confirm; if measure or draw dominates, prefetch tuning will not help — adjust item content instead. |
| 18 | - Wrong-phase state reads inside items (animation reads `state.value` in Composition) — use `../../recomposition/deferring-state-reads/SKILL.md`. |
| 19 | |
| 20 | ## Prerequisites |
| 21 | |
| 22 | - Compose Foundation **1.9+** for the `LazyLayoutCacheWindow` API. The cache window is a `@ExperimentalFoundationApi` factory `LazyLayoutCacheWindow(ahead: Dp, behind: Dp)` plumbed through `rememberLazyListState(cacheWindow = ...)` (or the equivalent grid/staggered-grid state). It is **NOT** a parameter on `LazyColumn` / `LazyRow` / `LazyVerticalGrid` / `LazyHorizontalGrid` directly. Every call site requires `@OptIn(ExperimentalFoundationApi::class)`. |
| 23 | - Compose Foundation **1.10+** for pausable composition in prefetch by default. On 1.10+ the prefetch composer can pause and resume across frames, so a single heavy item no longer blows a frame budget. |
| 24 | - Item-level hygiene already in place: `key`, `contentType`, stable item composables. Run `../optimizing-lazy-layouts/SKILL.md` first and confirm before tuning the window. |
| 25 | - Macrobenchmark module set up for `FrameTimingMetric`. See `../../measurement/generating-baseline-profiles/SKILL.md` for the Macrobenchmark scaffold. |
| 26 | |
| 27 | ## Workflow |
| 28 | |
| 29 | - [ ] **1. Confirm Compose Foundation version.** In `gradle/libs.versions.toml` or the relevant `build.gradle.kts`, verify `androidx.compose.foundation:foundation` is at **1.9.0+** (cache window) or **1.10.0+** (pausable prefetch on by default). If on 1.10+ and not measuring jank yet, **MUST** stop here — the default is good enough for most apps. |
| 30 | |
| 31 | - [ ] **2. Re-validate item-level fixes are in place.** Open `../optimizing-lazy-layouts/SKILL.md`. Every `items(...)` call has stable `key`, mixed feeds have `contentType`, item composables are skippable. Without this baseline, prefetch tuning is treating the symptom. |
| 32 | |
| 33 | - [ ] **3. Measure the baseline with Macrobenchmark `FrameTimingMetric` before changing anything.** Skydoves hot take #5: debug builds lie. Always m |