-
Notifications
You must be signed in to change notification settings - Fork 28
Add video renderer pool prewarming API #839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
- Add VideoRendererConfiguration public API for prewarming video renderers - Add internal configure method to VideoRendererPool for capacity management - Fix thread safety issue in ReusePool initialization - Eliminates 150-200ms UI hangs when video views are first created
/// Used for prewarming to add elements beyond initial capacity. | ||
/// | ||
/// - Parameter element: The pre-created element to add to the pool. | ||
func addToAvailable(_ element: Element) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method defies the Pool's purpose. The pool is responsible for creating its elements on demand.
/// | ||
/// - Parameter initialCapacity: The number of video renderers to pre-create. | ||
@MainActor | ||
static func configure(initialCapacity: Int) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what is happening on the reusePool initialisation. I don't see a reason for this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value is 0: https://github.com/GetStream/stream-video-swift/blob/develop/Sources/StreamVideoSwiftUI/Utils/VideoRendererPool/VideoRendererPool.swift#L20
This entire PR could be removed if that default value is changed, but I didn't want to change the default behavior for all users unexpectedly. So this PR is just a way to expose that number.
/// // Then later initialize StreamVideo as usual | ||
/// let streamVideo = StreamVideo(apiKey: apiKey, user: user, token: token) | ||
/// ``` | ||
public static func prewarm(count: Int = 2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method looks unnecessary. Can you elaborate more on why this is needed and why the existing warm up on init isn't sufficient?
let element = factory() | ||
available.append(element) | ||
// Initialize the pool with a set number of elements (thread-safe) | ||
queue.sync { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm i'm not sure about this one. Even without the sync, there aren't multiple threads accessing the initialiser at the same (if they were they would be creating different instances).
🎯 Goal
Eliminate UI blocking when video renderers are first created during video calls, improving user experience by preventing 150-200ms hangs.
📝 Summary
VideoRendererConfiguration.prewarm()
public API for creating video renderers proactivelyReusePool
initialization🛠 Implementation
New Public API:
Key Implementation Details:
prewarm(count:)
method that can be called from any threadawait Task.yield()
between each creation to prevent blocking the UI thread for extended periodsReusePool.init()
where initial elements were created outside of the thread-safequeue.sync
blockaddToAvailable()
method toReusePool
for adding pre-created elements beyond initial capacityTechnical Approach:
🧪 Manual Testing Notes
VideoRendererConfiguration.prewarm(count: 2)
early in app lifecycle, then create video call - should see immediate video appearance☑️ Contributor Checklist