Closed Bug 1546098 Opened 7 years ago Closed 7 years ago

nsRefreshDriver never stops for top-level documents in content processes, burning CPU

Categories

(Core :: Layout, defect)

defect
Not set
major

Tracking

()

RESOLVED FIXED
mozilla68
Tracking Status
firefox67 + fixed
firefox68 --- fixed

People

(Reporter: kennylevinsen, Assigned: kennylevinsen)

References

(Regression)

Details

(Keywords: regression)

Attachments

(1 file, 1 obsolete file)

https://bugzilla.mozilla.org/show_bug.cgi?id=1521786 changed the timer stop logic of nsRefreshDriver::Tick.

Before, any driver without observers would stop their timer on the next tick.

After 1521786 was merged, however, the logic changed to stopping observers in the following scenarios:

  • Immediately, if we are one of the following are true:
    • Throttled
    • Not a content process
    • Not a top-level document
    • Under test
    • In ASAP mode
  • In 4 seconds, if we have a incomplete ready-state and have not yet had a contentful paint.

This leaves top-level document drivers, and drivers on content-processes forever running unless they are explicitly frozen or throttled. This results in a very significant amount of wasted CPU, as the IPC vsync pump is left running.

That a running but empty nsRefreshDriver consumes so much CPU is somewhat of a separate issue.

I have attached a simple fix. It changes the condition so that the 4-second delay is used for incomplete, non-contentful drivers if we are not throttled/under test/in ASAP mode. In all other cases, the timer is stopped immediately.

Yeah, the condition introduced in bug 1521786 doesn't look quite right to me either. Easier fix is probably just an } else { StopTimer(); } at the end, probably...

Flags: needinfo?(bugs)
Status: UNCONFIRMED → NEW
Ever confirmed: true
Regressed by: 1521786
Keywords: regression

Thanks a lot for the report, Kenny!

} else { StopTimer(); } would work, but that leaves the construct as:

if (a) {
   StopTimer();
} else if (b) {
   DelayedStopTimer();
} else {
   StopTimer();
}

That looks a bit silly to me, which is why I instead did if (!a && b) { DelayedStopTimer(); } else { StopTimer(); }, with the exceptions for content processes and top-level documents removed from condition a.

nsRefreshDrivers belonging to fully-loaded documents in content processes
now correctly stop their timer when no observers are present.

Yes, totally agreed. It's a much more justifiable patch to uplift to beta though. Anyhow, probably not a huge deal either way.

The patch looks sane to me. I pushed it to the try server here:

https://treeherder.mozilla.org/#/jobs?repo=try&revision=8f4d1e21ce4e9b7d9579d5740fe0d792322cc8a0

But probably Olli or Farre should review it too. We're out of review flags in Bugzilla (patches are supposed to go via Phabricator these days), so needinfo it is :)

Ah, and as I say it you figure out how to use Phabricator, nice :)

Flags: needinfo?(bugs)
Attachment #9059816 - Attachment is obsolete: true
Assignee: nobody → bugzilla
Blocks: 1531756
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/4b7f613b9372 Ensure that nsRefreshDriver is always stopped when not needed. r=emilio
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla68
Regressions: 1546421

Emilio, since this is a 67 regression, could you request an uplift to beta? Thanks

Flags: needinfo?(emilio)

Comment on attachment 9059820 [details]
Bug 1546098 - Ensure that nsRefreshDriver is always stopped when not needed.

Beta/Release Uplift Approval Request

  • User impact if declined: More CPU usage when idling
  • Is this code covered by automated tests?: Yes
  • Has the fix been verified in Nightly?: Yes
  • Needs manual test from QE?: No
  • If yes, steps to reproduce:
  • List of other uplifts needed: None
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): Relatively simple patch that goes back to the behavior from before bug 1521786 in more cases.
  • String changes made/needed: none
Flags: needinfo?(emilio)
Attachment #9059820 - Flags: approval-mozilla-beta?
Regressions: 1546937

Comment on attachment 9059820 [details]
Bug 1546098 - Ensure that nsRefreshDriver is always stopped when not needed.

Low risk patch minimizing cpu usage when idling which is a recent 67 regression, uplift approved for 67 beta 15, thanks.

Attachment #9059820 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Has Regression Range: --- → yes
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: