Closed Bug 1679088 Opened 4 years ago Closed 3 years ago

High CPU usage (WindowServer) on macOS Big Sur

Categories

(Core :: Performance, defect)

Firefox 83
defect

Tracking

()

RESOLVED WORKSFORME
Performance Impact low

People

(Reporter: alexreg, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: perf:resource-use, power)

Attachments

(4 files)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.16; rv:83.0) Gecko/20100101 Firefox/83.0

Steps to reproduce:

On macOS Big Sur (11.0.1), I am now experiencing major issues with high CPU usage (mainly the WindowServer process, but also kerneltask). This has probably always existed to some extent, but became much worse upon upgrading to Big Sur. I have a lot of tabs open (several hundred), but only a handful are active at any time, thanks to Tab Session Manager. When I actively use Firefox (interact with web pages), the system slows down significantly, sometimes almost to a halt. This problem does not occur if Firefox is idle in the background, and certainly not when Firefox is not running.

Actual results:

High CPU & memory usage of WindowServer process.
Frequent freezing of UI on and generally very slow system.

Expected results:

Much lower CPU & memory usage of WindowServer.

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Widget: Cocoa
Product: Firefox → Core

I believe that tracking these bugs in the Performance component might be more effective, but please let me know if we should keep these in the Cocoa component since it's macOS specific.

Component: Widget: Cocoa → Performance

Hi Alex,

can you collect a profile for the period that you think the performance is bad by using the profiler (https://profiler.firefox.com/)?

And also if you can use about:memory to collect a memory report for the high memory usage, that would be great.

Flags: needinfo?(alexreg)

Hi Sean,

Attached are the profiling and memory report (well, two memory reports, the first before profiling, the second right after). Hopefully these reveal what's happening. It wasn't freezing up quite as badly as it did in the past — indeed, it's generally been better the last few days — but it's still far from ideal.

https://mega.nz/file/mctUEBbC#JCbg8eOhXQsrxijbpow_zNSt66O-20TVbKxlurWcZKA
https://mega.nz/file/7BlkXLwJ#Zs-zFaGZ8rVDtwqA4Lir10Cn7sUtu-x61uwspILruaE
https://mega.nz/file/2dkyhBha#aJc5wbNWl-aCIaHAvRcMiv6NJSWjluH11mVNVzURnPo

Alex

Flags: needinfo?(alexreg)

Thanks, Alex!

I uploaded your profile to the server: https://share.firefox.dev/3439GBO

So the first thing I noticed was the network thread in the main process was pretty busy, and I think a majority of them come from the extension process. I couldn't tell which extensions were making those requests. Can you try to disable extensions and see how it goes?

In addition to that, the compositor was pretty busy. By looking at a few random janks, I see mach_msg_trap was taking a lot of time. This seems to indicate that they were waiting for some inputs. There were also some long-running nsCycleCollector_collectSlice , I think which indicates the CC graph was huge.

Markus, can you see why the frames took a long time to render?

Flags: needinfo?(mstange.moz)

Here's an excerpt form the profile: https://share.firefox.dev/3nnKyNT

Wow, this looks really bad. We're triggering composites all the time. Thanks for reporting this!

I can see two problems:

  • The RefreshDriverTick markers say "Tick reasons: HasObservers (DocumentTimeline animations [Style])". This indicates that a CSS animation is running in the browser UI. We should find out which animation that is.
  • There's a consistent stream of PWindowGlobal::RawMessage calls, which indicates that an add-on is keeping us busy.

Alex, can you find out if one of your add-ons is responsible for the ongoing rendering? If you open a simple web page without any animations, and the Activity Monitor still shows high CPU usage for the WindowServer, then it's likely that Firefox is still triggering composites. It would be great if you could disable your add-ons one by one (or using bisection) until this problem stops happening.

It's also possible that Tab Session Manager is implemented inefficiently and keeps querying tab status, rather than listening to tab status changes. There's some evidence of that in the profile.

Also, could you try reproducing this problem in Firefox Nightly and getting another performance profile there? (It's a good idea to back up your Firefox profile first.)

Flags: needinfo?(mstange.moz) → needinfo?(alexreg)
Status: UNCONFIRMED → NEW
Ever confirmed: true

I appreciate you guys looking into this (and for uploading that profile to the server — I got errors when trying to do that). Indeed, it looks like an add-on is responsible for at least a large part of the slow-down, since just today I noticed the "Firefox Web Extensions" process was eating up a particularly high amount of CPU. I suspect it could be Tab Session Manager, which you mention. I suppose you also see the other add-ons I have installed from that profile (e.g., Tab Search, Ghostery)?

Disabling extensions and waiting for slow performance might be a bit inconvenient, because I have quite a few installed, but if you want to start by recommending a few I can try disabling individually, I'll have a go. And yep, I'll do another performance profile on Firefox nightly when I get a decent chunk of free time, hopefully this weekend.

Flags: needinfo?(alexreg)
Whiteboard: [qf:p3:resource]

Shouldn't recording the profile with IPC messages enabled (see edit settings) help here to figure out from which extension it's coming from? Given the amount of data that will be involved I would suggest that you only run the recording for a couple of seconds once you got Firefox into such a state.

Blocks: power-usage
Keywords: power

Update: unfortunately (or fortunately?) things haven't really be playing up too much lately. It could just be coincidence that it's been this way since I changed locations and no longer have my second monitor here (it was always plugged in previously)... but I suspect it's quite pertinent.

about:performance should help show the impact of addons - sort by type column

Flags: needinfo?(alexreg)
Attached image about:performance (deleted) —

about:performance view for add-ons

Flags: needinfo?(alexreg)
Attachment #9208929 - Attachment description: Screenshot 2021-03-14 at 00.32.56.png → about:performance
Attachment #9208929 - Attachment filename: Screenshot-2021-03-14-at-00.32.56.png → about-performance.png

It looks like if there's one culprit, it's probably Ghostery or Honey. Not sure even they are too bad though.

If I mouse-over Ghostery, it shows something like:

Dispatches since load: ~38,000,000 (~27,000,000ms)
Dispatches in last seconds: 206 (536ms)

And for Honey:

Dispatches since load: ~21,000,000 (3,000,000ms)
Dispatches in last seconds: ~9,000 (~1,000ms)

'~' signifies approximately, of course.

Any update on this? Firefox is still running incredibly slowly for me in general.

Attached file Spindump (deleted) —
Attached file Process Sample (deleted) —

Attached a couple of new files (spindump and process sample, using Activity Monitor) from a run today. The Firefox process itself had very high CPU usage (~300%).

Also, crashes are very regular, for the record.

(In reply to Alex from comment #12)

It looks like if there's one culprit, it's probably Ghostery or Honey. Not sure even they are too bad though.

So disabling these extensions didn't help? More helpful than an activity monitor process sample would be a gecko profile when the problem happens.

Yeah, disabling those didn't help.

I'm afraid it's not possible to do a Gecko profile, since Firefox itself freezes up at these times. Can you work with what you have?

Thanks.

Can you attach your about:support?

Also, in about:config, do you have layout.frame_rate set to a non-default value? The default is -1.

Flags: needinfo?(alexreg)
Attached file about:support (deleted) —
Flags: needinfo?(alexreg)

Sure, I've attached about:support. layout.frame_rate is indeed the default value of -1.

Markus, did you see anything that would be helpful in about:config to further investigate the issue?

Flags: needinfo?(mstange.moz)

Every time I watch something on YouTube the CPUs blowing so loud (MBP 16/2021). Both Firefox and WindowServer executables are taking high CPU % usage. Pre-version 90 it wasn't happing or the issue was less CPU intensive.

grabber, would you mind creating a Gecko profile via https://profiler.firefox.com/? When doing so please make sure to specifically select the Firefox Graphics preset by clicking the small triangle next to the toolbar button. If you could also check again with Firefox 89 that would be great.

Thanks!

Flags: needinfo?(grabber)

@Henrik

What do you need the JSON dump?(In reply to Henrik Skupin (:whimboo) [⌚️UTC+1] from comment #25)

grabber, would you mind creating a Gecko profile via https://profiler.firefox.com/? When doing so please make sure to specifically select the Firefox Graphics preset by clicking the small triangle next to the toolbar button. If you could also check again with Firefox 89 that would be great.

Thanks!

Here is the JSON dump and a screenshot showing the CPU usage (Activity Monitor from OSX).
https://drive.google.com/drive/folders/1zDeNlwUTgEHmbHkCEMxENqT3S0bPW1Ov?usp=sharing

Flags: needinfo?(grabber)

(In reply to grabber from comment #26)

Here is the JSON dump and a screenshot showing the CPU usage (Activity Monitor from OSX).
https://drive.google.com/drive/folders/1zDeNlwUTgEHmbHkCEMxENqT3S0bPW1Ov?usp=sharing

Yes, and thanks for sharing it with us. You could usually upload it yourself from within the profiler UI. There is an upload button in the top-right corner. Nevertheless I just did it for you. So the profile can be found at: https://share.firefox.dev/2VJsyEI

Markus, do you see something specific in that profile?

(In reply to Henrik Skupin (:whimboo) [⌚️UTC+1] from comment #27)

(In reply to grabber from comment #26)

Here is the JSON dump and a screenshot showing the CPU usage (Activity Monitor from OSX).
https://drive.google.com/drive/folders/1zDeNlwUTgEHmbHkCEMxENqT3S0bPW1Ov?usp=sharing

Yes, and thanks for sharing it with us. You could usually upload it yourself from within the profiler UI. There is an upload button in the top-right corner. Nevertheless I just did it for you. So the profile can be found at: https://share.firefox.dev/2VJsyEI

Markus, do you see something specific in that profile?

I don't know if it's correlated, but it seems that the high CPU usage happens when you have at least 2 Firefox windows open. I don't remember this happening with a single instance. On my daily usage I usually have multiple windows with dozen of tabs per window.

Are you still seeing this issue? We had some reports in bug 1722722 that things improved with macOS 11.5.2.

Independently, in Firefox 94, we've landed a patch which should reduce the WindowServer CPU usage as well (bug 1690687).

Flags: needinfo?(mstange.moz) → needinfo?(alexreg)

@mstange It seem to be better now, indeed. (I'm on 11.5.2.) CPU usage is still not as low as it ought to be, I'd say, but I'll report back once I updated macOS to latest and Firefox likewise. Thanks.

Flags: needinfo?(alexreg)

Thanks! Please reopen if you still see problems with the latest versions.

Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → WORKSFORME
Performance Impact: --- → P3
Whiteboard: [qf:p3:resource]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: