|
|
Chromium Code Reviews|
Created:
4 years, 6 months ago by alokp Modified:
4 years, 6 months ago CC:
chromium-reviews, CalebRouleau, ddorwin, feature-media-reviews_chromium.org, mark a. foltz, mlamouri (slow - plz ping) Base URL:
https://chromium.googlesource.com/chromium/src.git@master Target Ref:
refs/pending/heads/master Project:
chromium Visibility:
Public. |
DescriptionAvoid flooding main thread by caching state on media thread.
OnStatisticsUpdate and OnBufferedTimeRangesChanged fire much more
frequently than queried for. Posting all state change notifications
to the main thread causes potential performance issues. Cache state
not immediately required by PipelineClient on the media thread to
avoid having to post all state change notifications.
BUG=619975
Committed: https://crrev.com/8f268bb64214eab73f00216b96b919a1b2955999
Cr-Commit-Position: refs/heads/master@{#401457}
Patch Set 1 #
Total comments: 8
Patch Set 2 : rebase only #Patch Set 3 : addressed comments #Patch Set 4 : reverts reseting callbacks #
Total comments: 4
Patch Set 5 : added comment #Patch Set 6 : adds dcheck #Messages
Total messages: 25 (6 generated)
alokp@chromium.org changed reviewers: + sandersd@chromium.org
Perf tryjob is here: https://codereview.chromium.org/2073613002/
dalecurtis@chromium.org changed reviewers: + dalecurtis@chromium.org
I suspect this is now duplicating the logic in RendererMediaLog for similar reasons.
On 2016/06/16 16:33:57, DaleCurtis wrote: > I suspect this is now duplicating the logic in RendererMediaLog for similar > reasons. Do you mean this? https://cs.chromium.org/chromium/src/media/base/media_log.h AFAICT this patch only moves some variables from PipelineImpl to RendererWrapper. Can you point where exactly you see duplication of logic?
Probably the real fix is to stop sending so many of these at the source.
On 2016/06/16 17:06:36, DaleCurtis wrote: > Probably the real fix is to stop sending so many of these at the source. +mlamouri Yeah I would prefer that solution as well. It will be hard to match the frequency of state update notifications to the frequency at which state is queried for though. It will be a trade-off between performance and freshness of state but perhaps it will OK for some states depending on usage. Pipeline::GetStatistics(): Used to report prefixed media element attributes (webkitDecodedFrameCount, webkitDroppedFrameCount, webkitAudioDecodedByteCount, webkitVideoDecodedByteCount) and WMPI::ReportMemoryUsage. I do not know how long we plan to support the prefixed attributes. ReportMemoryUsage runs on a timer, so it will be quite easy to directly plumb OnStatisticsUpdate to ReportMemoryUsage. The calls to Pipeline::DidLoadingProgress and Pipeline::GetBufferedTimeRanges originate in blink HTMLMediaElement that I am not too familiar with. If there is a prescribed time interval for these events to fire, we can define these in PipelineImpl and change all media::Renderer implementations to respect it.
Description was changed from ========== Avoid flooding main thread by caching state on media thread. OnStatisticsUpdate and OnBufferedTimeRangesChanged fire much more frequently than queried for. Posting all state change notifications to the main thread causes potential performance issues. Cache state not immediately required by PipelineClient on the media thread to avoid having to post all state change notifications. BUG=619975 ========== to ========== Avoid flooding main thread by caching state on media thread. OnStatisticsUpdate and OnBufferedTimeRangesChanged fire much more frequently than queried for. Posting all state change notifications to the main thread causes potential performance issues. Cache state not immediately required by PipelineClient on the media thread to avoid having to post all state change notifications. BUG=619975 ==========
Attempt to reduce the number of OnStatisticsUpdate notifications at source is here: https://codereview.chromium.org/2079923002/ I am still waiting for the perf tryrun to see if it makes any difference.
Did you perf try run come through and show this fixed everything? https://codereview.chromium.org/2071503003/diff/1/media/base/pipeline_impl.cc File media/base/pipeline_impl.cc (right): https://codereview.chromium.org/2071503003/diff/1/media/base/pipeline_impl.cc... media/base/pipeline_impl.cc:72: SharedState() Just use = initialization. https://codereview.chromium.org/2071503003/diff/1/media/base/pipeline_impl.cc... media/base/pipeline_impl.cc:242: weak_factory_.InvalidateWeakPtrs(); Should be okay, we call Stop() and destruction on the same thread IIRC. Why did you move this? I think this should go after the else clause (where it is currently) otherwise the posted task will be triggered before. https://codereview.chromium.org/2071503003/diff/1/media/base/pipeline_impl.cc... media/base/pipeline_impl.cc:1059: base::AutoLock auto_lock(shared_state_lock_); Weird scoping isn't necessary anymore. You can just use lock + renderer.reset().
Yes it does fix perf regressions: http://storage.googleapis.com/chromium-telemetry/html-results/results-2016-06... The new regressions are for seek times that too small to begin with (< 3ms). So they may be just noise. https://codereview.chromium.org/2071503003/diff/1/media/base/pipeline_impl.cc File media/base/pipeline_impl.cc (right): https://codereview.chromium.org/2071503003/diff/1/media/base/pipeline_impl.cc... media/base/pipeline_impl.cc:72: SharedState() On 2016/06/22 15:21:15, DaleCurtis wrote: > Just use = initialization. Done. https://codereview.chromium.org/2071503003/diff/1/media/base/pipeline_impl.cc... media/base/pipeline_impl.cc:242: weak_factory_.InvalidateWeakPtrs(); On 2016/06/22 15:21:15, DaleCurtis wrote: > Should be okay, we call Stop() and destruction on the same thread IIRC. Why did > you move this? I think this should go after the else clause (where it is > currently) otherwise the posted task will be triggered before. It does not matter because we use WaitableEvent here. I find it cleaner to shutdown all notifications from the media thread before posting the stop task to the media thread (note that stop_cb is not posted back to the main thread; it gets Run on the media thread). I did not understand your "otherwise the posted task will be triggered before" comment. Which posted task did you mean? https://codereview.chromium.org/2071503003/diff/1/media/base/pipeline_impl.cc... media/base/pipeline_impl.cc:1059: base::AutoLock auto_lock(shared_state_lock_); On 2016/06/22 15:21:15, DaleCurtis wrote: > Weird scoping isn't necessary anymore. You can just use lock + renderer.reset(). If Renderer destructor is expensive, wouldn't we hold the lock for a long time unnecessarily?
https://codereview.chromium.org/2071503003/diff/1/media/base/pipeline_impl.cc File media/base/pipeline_impl.cc (right): https://codereview.chromium.org/2071503003/diff/1/media/base/pipeline_impl.cc... media/base/pipeline_impl.cc:242: weak_factory_.InvalidateWeakPtrs(); On 2016/06/22 at 16:27:54, alokp wrote: > On 2016/06/22 15:21:15, DaleCurtis wrote: > > Should be okay, we call Stop() and destruction on the same thread IIRC. Why did > > you move this? I think this should go after the else clause (where it is > > currently) otherwise the posted task will be triggered before. > > It does not matter because we use WaitableEvent here. I find it cleaner to shutdown all notifications from the media thread before posting the stop task to the media thread (note that stop_cb is not posted back to the main thread; it gets Run on the media thread). > > I did not understand your "otherwise the posted task will be triggered before" comment. Which posted task did you mean? I just meant that you're now invalidating WeakPtrs to tasks which may not have completed yet. You're also resetting these values before stop completes. This seems like a risky change.
https://codereview.chromium.org/2071503003/diff/1/media/base/pipeline_impl.cc File media/base/pipeline_impl.cc (right): https://codereview.chromium.org/2071503003/diff/1/media/base/pipeline_impl.cc... media/base/pipeline_impl.cc:242: weak_factory_.InvalidateWeakPtrs(); On 2016/06/22 20:40:39, DaleCurtis wrote: > On 2016/06/22 at 16:27:54, alokp wrote: > > On 2016/06/22 15:21:15, DaleCurtis wrote: > > > Should be okay, we call Stop() and destruction on the same thread IIRC. Why > did > > > you move this? I think this should go after the else clause (where it is > > > currently) otherwise the posted task will be triggered before. > > > > It does not matter because we use WaitableEvent here. I find it cleaner to > shutdown all notifications from the media thread before posting the stop task to > the media thread (note that stop_cb is not posted back to the main thread; it > gets Run on the media thread). > > > > I did not understand your "otherwise the posted task will be triggered before" > comment. Which posted task did you mean? > > I just meant that you're now invalidating WeakPtrs to tasks which may not have > completed yet. You're also resetting these values before stop completes. This > seems like a risky change. And those tasks would not complete anyways. We start waiting here after posting the stop task during which time the main thread will be suspended and none of the tasks posted on the main thread will run. After stop task completes, we reset the WeakPtr and callbacks. So it is functionally equivalent (except for unittests where we do not wait). That said this change is not needed. I will revert.
lgtm % one additional revert. https://codereview.chromium.org/2071503003/diff/60001/media/base/pipeline_imp... File media/base/pipeline_impl.cc (right): https://codereview.chromium.org/2071503003/diff/60001/media/base/pipeline_imp... media/base/pipeline_impl.cc:272: // Invalidate self weak pointers effectively canceling all pending This might break if we have any unittests not calling Stop() since we use DeleteSoon() on the media thread above, I think this part should be reverted as well. https://codereview.chromium.org/2071503003/diff/60001/media/base/pipeline_imp... media/base/pipeline_impl.cc:1055: std::unique_ptr<Renderer> renderer; Add a comment here then if you think it matters how long we hold the lock. I don't think it does, but fine with keeping it as is.
https://codereview.chromium.org/2071503003/diff/60001/media/base/pipeline_imp... File media/base/pipeline_impl.cc (right): https://codereview.chromium.org/2071503003/diff/60001/media/base/pipeline_imp... media/base/pipeline_impl.cc:272: // Invalidate self weak pointers effectively canceling all pending On 2016/06/22 21:00:06, DaleCurtis wrote: > This might break if we have any unittests not calling Stop() since we use > DeleteSoon() on the media thread above, I think this part should be reverted as > well. Doing this allows us to not have to check for IsRunning in various callbacks from media thread. Note the "if (!IsRunning())" changes to "DCHECK(IsRunning())", which is nice IMO. We could not do this before because the state was being cached in PipelineImpl and some unittests relied on the fact that some state-change notifications get triggered even after Stop. All PipelineImpl unittests call Stop, otherwise they will DCHECK in PipelineImpl destructor: https://cs.chromium.org/chromium/src/media/base/pipeline_impl_unittest.cc?q=p... https://cs.chromium.org/chromium/src/media/test/pipeline_integration_test_bas... Are you concerned about any other test? https://codereview.chromium.org/2071503003/diff/60001/media/base/pipeline_imp... media/base/pipeline_impl.cc:1055: std::unique_ptr<Renderer> renderer; On 2016/06/22 21:00:07, DaleCurtis wrote: > Add a comment here then if you think it matters how long we hold the lock. I > don't think it does, but fine with keeping it as is. Done.
Okay, then lets just add a DCHECK(!weak_factory_.HasWeakPtrs()); in the destructor.
On 2016/06/22 21:22:19, DaleCurtis wrote: > Okay, then lets just add a DCHECK(!weak_factory_.HasWeakPtrs()); in the > destructor. DONE. Although I needed to move the creation of WeakPtr<PipelineImpl> to PipelineImpl::Start so that tests that do not even start the pipeline do not hit DCHECK(!weak_factory_.HasWeakPtrs()). I think this is a good change. Now the weakptr is only valid between Start and Stop.
lgtm
The CQ bit was checked by alokp@chromium.org
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/2071503003/100001
Message was sent while issue was closed.
Description was changed from ========== Avoid flooding main thread by caching state on media thread. OnStatisticsUpdate and OnBufferedTimeRangesChanged fire much more frequently than queried for. Posting all state change notifications to the main thread causes potential performance issues. Cache state not immediately required by PipelineClient on the media thread to avoid having to post all state change notifications. BUG=619975 ========== to ========== Avoid flooding main thread by caching state on media thread. OnStatisticsUpdate and OnBufferedTimeRangesChanged fire much more frequently than queried for. Posting all state change notifications to the main thread causes potential performance issues. Cache state not immediately required by PipelineClient on the media thread to avoid having to post all state change notifications. BUG=619975 ==========
Message was sent while issue was closed.
Committed patchset #6 (id:100001)
Message was sent while issue was closed.
Description was changed from ========== Avoid flooding main thread by caching state on media thread. OnStatisticsUpdate and OnBufferedTimeRangesChanged fire much more frequently than queried for. Posting all state change notifications to the main thread causes potential performance issues. Cache state not immediately required by PipelineClient on the media thread to avoid having to post all state change notifications. BUG=619975 ========== to ========== Avoid flooding main thread by caching state on media thread. OnStatisticsUpdate and OnBufferedTimeRangesChanged fire much more frequently than queried for. Posting all state change notifications to the main thread causes potential performance issues. Cache state not immediately required by PipelineClient on the media thread to avoid having to post all state change notifications. BUG=619975 Committed: https://crrev.com/8f268bb64214eab73f00216b96b919a1b2955999 Cr-Commit-Position: refs/heads/master@{#401457} ==========
Message was sent while issue was closed.
Patchset 6 (id:??) landed as https://crrev.com/8f268bb64214eab73f00216b96b919a1b2955999 Cr-Commit-Position: refs/heads/master@{#401457} |
