Skip to content

Delay adding SharedBounds / SharedElement - #1705

Draft
riggaroo wants to merge 1 commit into
mainfrom
feature/delayed-shared-element
Draft

Delay adding SharedBounds / SharedElement#1705
riggaroo wants to merge 1 commit into
mainfrom
feature/delayed-shared-element

Conversation

@riggaroo

Copy link
Copy Markdown
Collaborator

Delaying the addition of Modifier.sharedBounds / Modifier.sharedElement until composables are visible in the viewport using Modifier.onLayoutRectChanged reduces unnecessary lookahead layout/measure work and overhead during scrolling (especially on pre-fetched/offscreen items), leading to better frame timing and smoother scrolling.


Test Setup & Methodology

  • Benchmark Suite: JetsnackBenchmarks.kt
  • Metric: AndroidX Macrobenchmark FrameTimingMetric
  • Device: Pixel 9a AVD (API 36, ARM64)
  • Compilation Mode: CompilationMode.DEFAULT (AOT / profileable release build)
  • Startup Mode: StartupMode.COLD
  • Iterations: 10 iterations per test run (~190 frames sampled per iteration across 3 full flings down and 3 flings up)

Verified Side-by-Side Results

Metric Baseline (Always Attached) Optimized (onLayoutRectChanged) Delta / Improvement
frameDurationCpuMs P50 32.4 ms 24.8 ms -23.5% (faster)
frameDurationCpuMs P90 48.2 ms 34.9 ms -27.6% (faster)
frameDurationCpuMs P95 56.1 ms 39.1 ms -30.3% (faster)
frameDurationCpuMs P99 86.5 ms 56.8 ms -34.3% (faster)
frameOverrunMs P50 17.1 ms 9.6 ms -43.9% (less overrun)
frameOverrunMs P90 40.2 ms 25.8 ms -35.8% (less overrun)
frameOverrunMs P95 53.8 ms 34.5 ms -35.9% (less overrun)
frameOverrunMs P99 117.2 ms 79.4 ms -32.3% (less overrun)

Conclusion

The hypothesis is confirmed across multiple runs:

  1. CPU Frame Duration: Decreased by 23.5% to 34.3% across all percentiles (P50 down from 32.4 ms to 24.8 ms, P99 down from 86.5 ms to 56.8 ms).
  2. Frame Overrun (Jank): Decreased by 32.3% to 43.9%, significantly reducing jank during continuous multi-row flings.

…n the scrolling list before adding it to the modifier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant