Bug 1675543 - Cache PerformanceResourceTiming's StartTime r=smaug

PerformanceResourceTiming recalculates the startTime every time when
`StartTime()` method is called, which slows down `GetEntriesByName()`
due to this method requires `StartTime()` to order the entries.

In addition to that, there's not need to recalculate it every time, since all
required timings are already set when the `PerformanceTimingData`
object is first created.

This patch calculates the `startTime` when it's accessed first time
and caches it.

Differential Revision: https://phabricator.services.mozilla.com/D96295
This commit is contained in:
Sean Feng 2020-11-10 01:30:24 +00:00
parent b5623086d5
commit 9f50bffe4a
2 changed files with 13 additions and 7 deletions

View File

@ -48,16 +48,19 @@ DOMHighResTimeStamp PerformanceResourceTiming::StartTime() const {
// Ignore zero values. The RedirectStart and WorkerStart values
// can come from earlier redirected channels prior to the AsyncOpen
// time being recorded.
DOMHighResTimeStamp redirect =
mTimingData->RedirectStartHighRes(mPerformance);
redirect = redirect ? redirect : DBL_MAX;
if (mCachedStartTime.isNothing()) {
DOMHighResTimeStamp redirect =
mTimingData->RedirectStartHighRes(mPerformance);
redirect = redirect ? redirect : DBL_MAX;
DOMHighResTimeStamp worker = mTimingData->WorkerStartHighRes(mPerformance);
worker = worker ? worker : DBL_MAX;
DOMHighResTimeStamp worker = mTimingData->WorkerStartHighRes(mPerformance);
worker = worker ? worker : DBL_MAX;
DOMHighResTimeStamp asyncOpen = mTimingData->AsyncOpenHighRes(mPerformance);
DOMHighResTimeStamp asyncOpen = mTimingData->AsyncOpenHighRes(mPerformance);
return std::min(asyncOpen, std::min(redirect, worker));
mCachedStartTime.emplace(std::min(asyncOpen, std::min(redirect, worker)));
}
return mCachedStartTime.value();
}
JSObject* PerformanceResourceTiming::WrapObject(

View File

@ -179,6 +179,9 @@ class PerformanceResourceTiming : public PerformanceEntry {
// The same initial requested URI as the `name` attribute.
nsCOMPtr<nsIURI> mOriginalURI;
private:
mutable Maybe<DOMHighResTimeStamp> mCachedStartTime;
};
} // namespace dom