mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 23:02:20 +00:00
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:
parent
b5623086d5
commit
9f50bffe4a
@ -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(
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user