Delay adding SharedBounds / SharedElement - #1705
Open
riggaroo wants to merge 3 commits into
Open
Conversation
…n the scrolling list before adding it to the modifier
riggaroo
marked this pull request as ready for review
August 20, 2026 15:21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Executive Summary
Optimizing lookahead shared element modifiers and Compose runtime
CompositionLocalusage resulted in dramatic frame timing improvements across both high-frequency scrolling and navigation transitions:52.9%(from10.4 msdown to4.9 ms), and P99 frame latency dropped by64.8%(from45.4 msdown to16.0 ms), completely eliminating frame drops during scroll flings.14.1 msdown to9.5 ms, and P99 frame overrun improved from+9.9 ms(dropped frames) to-2.2 ms(zero dropped frames throughout the entire forward and reverse transition).1. Feed Scrolling Benchmark (
scrollFeedFrameTiming)Test Action: Rapid vertical flings down through the feed and back up.
Frame Duration (CPU Time per Frame)
10.4 ms4.9 ms-5.5 ms17.4 ms8.6 ms-8.8 ms21.9 ms10.6 ms-11.3 ms45.4 ms16.0 ms-29.4 msFrame Overrun (Frame Deadline Margin @ 60Hz / 16.6ms)
Negative values represent headroom before missing a vsync deadline; positive values represent dropped frames.
-5.8 ms-11.2 ms+1.7 ms(Jank / Dropped)-7.5 ms(Smooth)+5.9 ms(Jank / Dropped)-5.4 ms(Smooth)+29.7 ms(Severe Jank)+0.3 ms2. Snack Detail Navigation Benchmark (
navigateSnackDetailFrameTiming)Test Action: Tap snack card (Forward shared transition) ➔ Snack Detail Screen ➔ Press Back (Reverse shared transition).
Frame Duration (CPU Time per Frame)
8.0 ms6.4 ms-1.6 ms14.1 ms9.5 ms-4.6 ms16.1 ms10.4 ms-5.7 ms22.3 ms13.7 ms-8.6 msFrame Overrun (Frame Deadline Margin @ 60Hz / 16.6ms)
-3.3 ms-9.9 ms+1.3 ms(Jank / Dropped)-6.7 ms(Smooth)+5.0 ms(Jank / Dropped)-5.8 ms(Smooth)+9.9 ms(Jank / Dropped)-2.2 ms(Smooth)3. Implemented Optimizations
1. On-Demand
sharedBoundsAttachment via Layout Rect TrackingLazyRowitems unconditionally attached 5Modifier.sharedBoundslookahead layout nodes (card bounds, background, image, title, tagline). During vertical scroll flings, Compose prefetchers executed expensive lookahead passes for off-screen cards (compose:lazy:prefetch:execute:urgenttaking up to 16.1 ms per item).onLayoutRectChangedto cards and dynamically attachedsharedBoundsonly when items enter the visible window (fractionVisibleInWindow() > 0f).2.
staticCompositionLocalOffor Navigation & Shared Transition ScopesLocalNavAnimatedVisibilityScopeandLocalSharedTransitionScopewere defined with dynamiccompositionLocalOf. Reading.currentacross dozens of lazy card items registered active snapshot state observers in Compose's slot table.staticCompositionLocalOf, eliminating runtime observer tracking since scope references are invariant within a destination.3. Conditional Bypass in
JetsnackSurfaceJetsnackSurfaceunconditionally inserted aCompositionLocalProvider(LocalContentColor provides contentColor)subtree for every card, image container, and badge.contentColoralready matchesLocalContentColor.current.4. Scope Reference Hoisting
LocalSharedTransitionScope.currentandLocalNavAnimatedVisibilityScope.currentinside every leaf item created redundant slot table lookups during rapid item recycling.SnackCollectionand passed them down as parameters toHighlightedSnacks/Snacksand child items.