Bug 1692213 - Use raw timestamp internally for PerformanceEventTiming r=smaug

Currently, whenever the algorithm requires to get timestamps, it'll
try to get the corresponding precision reduced timestamps. However,
this creates some memory overhead because the calculation of precision
reduced timestamps. So instead of always generating the precision
reduced timestamps, we use the raw timestamps internally to avoid
generating precision reduced timestamps unnecessarily.

Differential Revision: https://phabricator.services.mozilla.com/D105829
This commit is contained in:
Sean Feng 2021-02-22 15:36:45 +00:00
Родитель 1df7755bd6
Коммит 5c67d2bffc
3 изменённых файлов: 12 добавлений и 3 удалений

Просмотреть файл

@ -138,7 +138,7 @@ bool PerformanceEventTiming::ShouldAddEntryToBuffer(double aDuration) const {
return true; return true;
} }
MOZ_ASSERT(GetEntryType() == nsGkAtoms::event); MOZ_ASSERT(GetEntryType() == nsGkAtoms::event);
return Duration() >= aDuration; return RawDuration() >= aDuration;
} }
bool PerformanceEventTiming::ShouldAddEntryToObserverBuffer( bool PerformanceEventTiming::ShouldAddEntryToObserverBuffer(

Просмотреть файл

@ -67,6 +67,11 @@ class PerformanceEventTiming final
mDuration = aDuration; mDuration = aDuration;
} }
// nsRFPService::ReduceTimePrecisionAsMSecs might causes
// some memory overhead, using the raw timestamp internally
// to avoid calling in unnecessarily.
DOMHighResTimeStamp RawDuration() const { return mDuration; }
DOMHighResTimeStamp Duration() const override { DOMHighResTimeStamp Duration() const override {
if (mCachedDuration.isNothing()) { if (mCachedDuration.isNothing()) {
mCachedDuration.emplace(nsRFPService::ReduceTimePrecisionAsMSecs( mCachedDuration.emplace(nsRFPService::ReduceTimePrecisionAsMSecs(
@ -77,6 +82,10 @@ class PerformanceEventTiming final
return mCachedDuration.value(); return mCachedDuration.value();
} }
// Similar as RawDuration; Used to avoid calling
// nsRFPService::ReduceTimePrecisionAsMSecs unnecessarily.
DOMHighResTimeStamp RawStartTime() const { return mStartTime; }
DOMHighResTimeStamp StartTime() const override { DOMHighResTimeStamp StartTime() const override {
if (mCachedStartTime.isNothing()) { if (mCachedStartTime.isNothing()) {
mCachedStartTime.emplace(nsRFPService::ReduceTimePrecisionAsMSecs( mCachedStartTime.emplace(nsRFPService::ReduceTimePrecisionAsMSecs(

Просмотреть файл

@ -245,10 +245,10 @@ void PerformanceMainThread::DispatchPendingEventTimingEntries() {
RefPtr<PerformanceEventTiming> entry = RefPtr<PerformanceEventTiming> entry =
mPendingEventTimingEntries.popFirst(); mPendingEventTimingEntries.popFirst();
entry->SetDuration(renderingTime - entry->StartTime()); entry->SetDuration(renderingTime - entry->RawStartTime());
IncEventCount(entry->GetName()); IncEventCount(entry->GetName());
if (entry->Duration() >= kDefaultEventTimingMinDuration) { if (entry->RawDuration() >= kDefaultEventTimingMinDuration) {
QueueEntry(entry); QueueEntry(entry);
} }