Closed Bug 1768920 Opened 4 years ago Closed 3 years ago

nsUserIdleService causes pointless CPU wake-ups every 5s

Categories

(Core :: Widget, defect, P3)

defect

Tracking

()

RESOLVED FIXED
111 Branch
Tracking Status
firefox111 --- fixed

People

(Reporter: florian, Assigned: florian)

References

(Blocks 1 open bug)

Details

(Keywords: perf:resource-use, power)

Attachments

(2 files)

When Firefox is really idle and the user not touching the machine, the "nsUserIdleService::SetTimerExpiryIfBefore" runnable is the most frequent one that executes, every 5s.

Example profile: https://share.firefox.dev/3Pd4qkU

This behavior was implemented at https://searchfox.org/mozilla-central/rev/88792eff309001778cb2431f2a0ed92f8f3c258a/widget/nsUserIdleService.cpp#862-880 in bug 720493, apparently to workaround a bug that wasn't well understood at the time.

We should try and change that so that the idle service only causes wake-up if there's actually an observer that wants to be notified.

The severity field is not set for this bug.
:spohl, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(spohl.mozilla.bugs)
Severity: -- → S2
Flags: needinfo?(spohl.mozilla.bugs)
Priority: -- → P2
Severity: S2 → S3
Priority: P2 → P3
Duplicate of this bug: 596044
Assignee: nobody → florian
Status: NEW → ASSIGNED

This changes the behavior in a few ways:

  • the 'back' notification is now only fired when a new user event has been received by Firefox, rather than by any application on the entire system.
  • the 'back' notification will fire immediately when Firefox receives a new event. Before the patch is was fired within 5s of the user returning on some plateforms (eg. Mac) and immediately on some other platforms that already called ResetIdleTimeout (windows, gtk, android). I'm not sure if these existing calls to ResetIdleTimeout are really needed, nor if they add significant overhead.
  • when an idle observer has been notified of 'idle', it won't be notified again until Firefox receives events. Before the patch, if the user used other applications while Firefox was in the background, we would keep sending back and idle notifications to our idle observers. This behavior was probably initially intended when the nsUserIdleService was introduced to support the use case of instant messaging clients, but doesn't seem to match the expectations of the existing consumers of the service.

Depends on D166305

Blocks: 834343
Pushed by fqueze@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/eab0a62da795 Add profiler markers to see which code uses user idle observers and when they fire, r=dthayer. https://hg.mozilla.org/integration/autoland/rev/6c80af296399 Avoid polling every 5 seconds in nsUserIdleService, r=dthayer,geckoview-reviewers,owlish.
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 111 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: