Open Bug 1912758 Opened 6 months ago Updated 3 months ago

Extreme CPU usage spike when typing into text fields

Categories

(Core :: Performance, defect)

Firefox 129
defect

Tracking

()

UNCONFIRMED
Performance Impact pending-needinfo

People

(Reporter: timon, Unassigned, NeedInfo)

Details

Attachments

(1 file)

Attached image firefox-spike.png

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0

Steps to reproduce:

The bug seems to occur the most extreme on mastodon.social
I just need to start to type a new post.
This happens to a lesser degree elsewhere too when typing.
Loading multiple websites causes similar issues.

Actual results:

CPU usage of both Firefox and the Windows Kernel sky rocket and RAM usage increases by few GB. See attached picture of how it looks during typing, before it was sitting at 0.5% CPU utilization and 8.2GB then it jumped to 13.1% and 12GB RAM usage while system process spiked to 30.7% from previously 0.7% CPU utilization.

Looking at a system trace with WPA the Kernel spends a huge amount of time zeroing pages. There is a known issue in the Windows 10 kernel around this which seems to have occurred in Chrome as well at some point:
https://randomascii.wordpress.com/2022/07/11/slower-memory-zeroing-through-parallelism/

Expected results:

No 10-30x increase in CPU usage from typing into text fields or loading websites and no jump in RAM usage from typing.

Ok the insane memory increase on mastodon.social can be faulted towards an extension.
What remains is that whenever a lot of memory is allocated and subsequently released (like when several websites load) it causes the Windows Kernel to also have this huge CPU spike due to clearing a lot of tiny pages and spending a lot of time in a spinlock. That was not there in the past, did something changed in the way memory is handled in the past versions?

Component: Untriaged → Performance
Product: Firefox → Core

This bug was moved into the Performance component.

:timon, could you make sure the following information is on this bug?

  • For slowness or high CPU usage, capture a profile with http://profiler.firefox.com/, upload it and share the link here.
  • For memory usage issues, capture a memory dump from about:memory and attach it to this bug.
  • Troubleshooting information: Go to about:support, click "Copy raw data to clipboard", paste it into a file, save it, and attach the file here.

If the requested information is already in the bug, please confirm it is recent.

Thank you.

Flags: needinfo?(timon)

I was unable to reproduce any high CPU usage in the latest Firefox 130.0.1 version on Windows10 x64 when following the steps from Comment 0. @Timon, could you confirm if the issue still persists in the latest Firefox version? If so, please provide the additional details requested in Comment 2.

Sorry for the delay. Here a performance profile: https://share.firefox.dev/3BlLsGi
What I did during the spike was load a few tabs.
The high RAM utilization issue I initially mentioned does not persist, the spiking in CPU usage does persist and seems to still mostly be related to the mentioned zeroing of RAM pages. Anytime Firefox is busy allocating memory it starts using a lot of CPU. If I have a website that keeps on allocating that can keep CPU usage very high consistently although not much is happening other than that. In that case I need to restart the browser to fix it.

Flags: needinfo?(timon)
Summary: Extreme CPU and RAM usage spike when typing into text fields → Extreme CPU usage spike when typing into text fields

Here another trace, this is from the same session but the computer was put to sleep over night and after resuming the browser was stuck at 10-30% CPU utilization. No interaction with Firefox necessary.
It seems to spend a lot of time in ZwWaitForAlertByThreadId
https://share.firefox.dev/4dmCvKm

Do those profiles contain the time during which you were typing in the text field? The CPU usage I see in them is mostly from loading pages.

Ah yea the description and title may need updating. It's not isolated to text fields as described in the second comment. Just where I first noticed a correlation but it completely depends on the website too if its an issue or not. The only thing that I can see atm. being consistent in these cases is RAM being allocated for whatever task is run and the Windows Kernel spending a ton of time in waiting on spin locks.
This got worse each time I upgraded to a higher end CPU with more logical cores.

(In reply to Timon from comment #4)

Sorry for the delay. Here a performance profile: https://share.firefox.dev/3BlLsGi
What I did during the spike was load a few tabs.
The high RAM utilization issue I initially mentioned does not persist, the spiking in CPU usage does persist and seems to still mostly be related to the mentioned zeroing of RAM pages. Anytime Firefox is busy allocating memory it starts using a lot of CPU. If I have a website that keeps on allocating that can keep CPU usage very high consistently although not much is happening other than that. In that case I need to restart the browser to fix it.

The most obvious questionable CPU usage I see in this profile appears to be coming from an extension called 'VideoDownload Helper'.

During the loading of the pages themselves there is high CPU usage in the parent but that in itself is expected, could you take a profile where pages are loaded and high CPU usage persists well after the load. After the GCs are done in these profiles I don't see any high CPU usage.

Performance Impact: --- → pending-needinfo
Flags: needinfo?(timon)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: