Closed Bug 1652000 Opened 4 years ago Closed 4 years ago

about:processes uses too much CPU

Categories

(Core :: DOM: Content Processes, defect, P2)

defect

Tracking

()

RESOLVED FIXED
mozilla80
Fission Milestone M6b
Tracking Status
firefox80 --- fixed

People

(Reporter: Yoric, Assigned: Yoric)

References

Details

Attachments

(3 files, 3 obsolete files)

Apparently, about:processes takes 25-30% on some machines. Let's fix that.

Ryan, could you tell us more? Which OS are you using?

Flags: needinfo?(ryanvm)
Attached file about:support
Flags: needinfo?(ryanvm)

Thanks.

So, it looks like calls to Thread32Next are expensive and we're calling it quite often. Looking at it a bit more in detail, we're doing the following:

  • For each process
    • Take a snapshot of the entire OS
    • Walk through all the threads of this snapshot
      • Discard the threads that do not match the current process

Looks like we could be quite a bit more efficient by taking a single snapshot and iterating through it once. This would mean reworking the calling code in ChromeUtils to avoid assuming that we handle each process separately.

I might also move this code to ProcessToolsService, to be determined.

So, I'd say:

  1. Rework ProcInfo::GetProcInfo to take as argument an array of partially-filled ProcInfo instead of a single ProcInfo.
  2. Rework the calling code from ChromeUtils::RequestProcInfo accordingly.

The current implementation of GetProcInfo is inefficient under Windows as it takes
one snapshot of the entire OS per process, then needs to walk each of these global
snapshots looking for information on the single process.

This patch changes the API and client caller RequestProcInfo to be able to share
a single snapshot.

Assignee: nobody → dteller
Status: NEW → ASSIGNED

GetProcInfo relies upon Thread32First/Thread32Next, both of which are quite CPU-expensive.
This patch refactors GetProcInfo to decrease the number of calls to Thread32Next from
~O(T * P) to ~O(T), where T is the number of threads on the OS and P is the number of Firefox
processes launched.

Depends on D83335

Severity: -- → S2
Fission Milestone: --- → M6b
Priority: -- → P2
Attachment #9163222 - Attachment description: Bug 1652000 - Refactor Windows implementation of GetProcInfo to use a single snapshot;r?tarek → Bug 1652000 - Refactoring ChromeUtils::RequestProcInfo to place a single request to GetProcInfo;r?tarek
Attachment #9163285 - Attachment is obsolete: true
Attachment #9163590 - Attachment is obsolete: true
Attachment #9163221 - Attachment is obsolete: true
Attachment #9163221 - Attachment is obsolete: false
Attachment #9163221 - Attachment description: Bug 1652000 - Refactoring ChromeUtils::RequestProcInfo to place a single request to GetProcInfo;r?tarek → Bug 1652000 - Refactoring ChromeUtils::RequestProcInfo to place a single request to GetProcInfo;r?tarek!
Attachment #9163222 - Attachment is obsolete: true

Florian, Ryan, once this patch has landed, could you confirm that it improves CPU usage on your Windows machines?

Flags: needinfo?(ryanvm)
Pushed by dteller@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/22bb2a5032b7
Refactoring ChromeUtils::RequestProcInfo to place a single request to GetProcInfo;r=tarek
https://hg.mozilla.org/integration/autoland/rev/5f02a357671c
A little lifetime documentation;r=nika
Attachment #9163223 - Attachment description: Bug 1652000 - A little lifetime documentation;r?nika → Bug 1652000 - A little lifetime documentation;r?nika!
Flags: needinfo?(dteller)

I hope we're taking the toolhelp32 snapshot off main thread as well; that call is super expensive.

Pushed by dteller@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/0a6cb920a247
Refactoring ChromeUtils::RequestProcInfo to place a single request to GetProcInfo;r=tarek,geckoview-reviewers,agi
https://hg.mozilla.org/integration/autoland/rev/69dbf38f4071
A little lifetime documentation;r=nika
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla80

Thanks for the backout!

Flags: needinfo?(dteller)

So, tests confirm that if I remove the 3-liner that was supposed to fix bug 1642257, we don't crash anymore.

Let's land the part that works and deal with the other bug in the other bug.

Pushed by dteller@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/d52e4d4a3788
Refactoring ChromeUtils::RequestProcInfo to place a single request to GetProcInfo;r=tarek,geckoview-reviewers,agi
https://hg.mozilla.org/integration/autoland/rev/4603073c15cb
A little lifetime documentation;r=nika
Status: REOPENED → RESOLVED
Closed: 4 years ago4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla80

So we had a tid of 0 under Windows once.

Odd.

(In reply to David Teller [:Yoric] (please use "needinfo") from comment #11)

Florian, Ryan, once this patch has landed, could you confirm that it improves CPU usage on your Windows machines?

CPU usage now seems to be 2-4% of one core. Example profile: https://share.firefox.dev/2ZScj7G

CPU usage seems better for me too.

Flags: needinfo?(ryanvm)

We'll call this a victory, then!

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: