Open Bug 1384291 Opened 7 years ago Updated 2 years ago

Consider removing TimeoutManager::mThrottleTimeoutsTimer

Categories

(Core :: DOM: Core & HTML, enhancement, P3)

enhancement

Tracking

()

People

(Reporter: bkelly, Assigned: farre)

References

Details

Attachments

(1 file, 1 obsolete file)

Bug 1384037 points out that we are firing the mThrottleTimeoutsTimer a lot. This makes sense since we start it for every window. This is a lot of overhead considering the timer simply sets a flag when it fires. We should consider removing the mThrottleTimeoutsTimer. Instead we could simply note the TimeStamp::Now() when the timer is currently started. In cases where we care about throttling we can then write a MaybeStartThrottling() method like this: void TimeoutManager::MaybeStartThrottling(const TimeStamp& now) { if (mThrottleTimeouts || gTimeoutThrottlingDelay <= 0 || mWindow.IsSuspended()) { return; } TimeDuration elapsed = now - mStartTime; mThrottleTimeouts = (elapsed.ToMilliseconds() >= gTimeoutThrottlingDelay); } We then call MaybeStartThrottling() in SetTimeout(), RescheduleTimeout(), etc. This would allow us to start throttling when appropriate without incurring the cost of a heap allocation, nsITimer schedule, runnable dispatch, etc. We trade this off against the simple cost of storing a TimeStamp in TimeoutManager. Andreas, what do you think?
Flags: needinfo?(afarre)
Yeah, I really like this. This is the same way we resolved collecting telemetry without a timer.
Flags: needinfo?(afarre)
Priority: -- → P2
Ben, what do you think about this? I actually use mStartTime similarly to how the timer was used, and by adding a caching getter for the throttling enabled flag we get a consistent way of setting it. Also, this way we can use checking if mStartTime has a value to determine if we haven't started the pending state.
Assignee: nobody → afarre
Attachment #8890846 - Flags: feedback?(bkelly)
Comment on attachment 8890846 [details] [diff] [review] 0001-Bug-1384291-Remove-TimeoutManager-mThrottleTimeoutsT.patch Review of attachment 8890846 [details] [diff] [review]: ----------------------------------------------------------------- Looks great! ::: dom/base/TimeoutManager.cpp @@ +1264,3 @@ > } > > + if (!mStartTime) { I think we try to use mStartTime.IsNull() for TimeStamp objects. I didn't know it had a boolean cast operator.
Attachment #8890846 - Flags: feedback?(bkelly) → feedback+
Moving to p3 because no activity for at least 1 year(s). See https://github.com/mozilla/bug-handling/blob/master/policy/triage-bugzilla.md#how-do-you-triage for more information
Priority: P2 → P3
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: