Skip to content

Conversation

Amud
Copy link

@Amud Amud commented Sep 18, 2025

MicrosoftTeams-video.mp4

Adds a LazyColumn-based shortform demo that optimizes a single-ExoPlayer setup with preloading, addressing performance concerns raised in #1853.

Related issue

Fixes #1853.

Background

  • Initial frame delays with single player + PreloadManager
  • Lag on first video and during transitions
  • Performance gap vs a multi-player pool approach

Solution

  • Window-based media management
    • Sliding window (~10 items) with dynamic load/unload based on scroll
    • Reduces memory pressure while maintaining smooth playback
  • Optimized preloading
    • TargetPreloadStatusControl preloads 3–5s for adjacent items
    • Preloads items at distance ±1 and ±2
  • Reactive cache tracking
    • mutableStateMapOf tracks cache completion
    • Thumbnails load only after content is cached
  • Single player benefits
    • Lower memory use than a 3‑player pool
    • Simpler state management with smooth transitions

Performance (observed)

  • Reduced initial frame delay via targeted preloading
  • Windowing avoids memory exhaustion
  • Cache-aware thumbnails improve perceived responsiveness
  • Consistent transition smoothness across indices

Implementation highlights

  • LazyColumnPlayerManager: sliding window + preload management
  • LazyColumnTargetPreloadStatusControl: 3–5s buffer strategy
  • SinglePlayerSetupHelper: optimized load control and cache
  • Compose UI reacts to cache status changes

Testing

  • Transitions across all items
  • Smooth playback without noticeable frame drops
  • Stable memory during extended scrolling
  • No rendering delays after initial cache warm-up

Entry point

Adds a “LazyColumn” button in MainActivity alongside the existing ViewPager demo.

…ndroidx#1853)

Implements optimized single-player architecture for shortform content that
addresses the performance issues described in androidx#1853.

Key optimizations:
- Sliding window management (10 items) with dynamic loading
- Aggressive preloading for adjacent items (3-5 second buffers)
- Reactive cache status tracking prevents premature thumbnail loading
- Optimized load control settings for quick start (500ms buffer)

This provides a performant alternative to multi-player pools while
maintaining lower memory overhead and simpler architecture.

Fixes androidx#1853
@Amud
Copy link
Author

Amud commented Oct 13, 2025

hi @oceanjules , Please let me know if there are any feedbacks on this PR.

@oceanjules
Copy link
Contributor

Hi Amud, sorry for a delay, thank you for waiting! This is a great contribution and we appreciate the effort you've put into addressing the performance issues with the short-form demo.

However, this pull request has grown quite large and mixes several distinct concepts. You PR adds production-like features which is a great example of how to build a short-form video feeds, but not a good example for a developer who wants to understand a single feature of the Media3 library. In a real-world app, this is exactly what would be expected from a developer to make a smooth experience for a user. However, our demo apps are not made to be standalone apps, but instead showcase particular features of the library, grouped by domain.

There are users who might want a purely java+xml layouts example of using PreloadManager without having to untangle it from Compose UI. There are users who would want the Session Demo to be in Compose (#2418). Someone interested in using Media3 with Compose would be overwhelmed by the custom caching and preloading implementation.

At the same time, we are not ready to productionise parts of this PR either because we do not have strong guidance about player management logic and how to keep a pool of players, what algorithm to use to evict old players and how to initialize more. We often use our own demo apps to ensure the feature will land well which is why we want them to be as lightweight as possible. When people report bugs, they should be able to quickly build the app and give us short reproduction steps.

We can leave this PR for any developers who stumble upon it and want to study your code to get some inspiration for building a performant, short-form video app - although for better visibility I would advise you to make a Medium article :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blank/Slow Frame Render for videos (Shortform Demo)

2 participants