Bug 1499850 - make MediaTimer slightly more efficient; r=pehrsons
authorNathan Froyd <froydnj@mozilla.com>
Thu, 18 Oct 2018 07:00:11 -0400
changeset 500376 0162bb225b88cfda9b702d88464d48fbf1f372ee
parent 500375 9e81f9458926dbb1796ac5c3c0b06fa1ee1d10e9
child 500377 2da6504c901e9474566aa1663d907bd58bed9edb
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspehrsons
bugs1499850
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1499850 - make MediaTimer slightly more efficient; r=pehrsons Instead of creating a timer and then setting the timer's target, we can determine the timer's target and pass it in directly when the timer is created. This reordering of steps is slightly more efficient, since SetTarget() is both a virtual call and requires locking, both of which can be skipped if we know the target at timer creation time.
dom/media/MediaTimer.cpp
--- a/dom/media/MediaTimer.cpp
+++ b/dom/media/MediaTimer.cpp
@@ -16,29 +16,28 @@
 
 namespace mozilla {
 
 NS_IMPL_ADDREF(MediaTimer)
 NS_IMPL_RELEASE_WITH_DESTROY(MediaTimer, DispatchDestroy())
 
 MediaTimer::MediaTimer(bool aFuzzy)
   : mMonitor("MediaTimer Monitor")
-  , mTimer(NS_NewTimer())
   , mCreationTimeStamp(TimeStamp::Now())
   , mUpdateScheduled(false)
   , mFuzzy(aFuzzy)
 {
   TIMER_LOG("MediaTimer::MediaTimer");
 
   // Use the SharedThreadPool to create an nsIThreadPool with a maximum of one
   // thread, which is equivalent to an nsIThread for our purposes.
   RefPtr<SharedThreadPool> threadPool(
     SharedThreadPool::Get(NS_LITERAL_CSTRING("MediaTimer"), 1));
   mThread = threadPool.get();
-  mTimer->SetTarget(mThread);
+  mTimer = NS_NewTimer(mThread);
 }
 
 void
 MediaTimer::DispatchDestroy()
 {
   // Hold a strong reference to the thread so that it doesn't get deleted in
   // Destroy(), which may run completely before the stack if Dispatch() begins
   // to unwind.