element-hq / element-hq/element-web
Constant CPU wakeups and CPU usage while the web version of Element is unfocused in a background tab
- Dominant language
- TypeScript
- Stars
- 13.5k
- Forks
- 2.8k
- PR merge metrics
- PR metrics pending
Description
### Steps to reproduce
1. Launch Firefox with just one normal static website loaded (ex: this GitHub ticket), observe CPU usage to be roughly 0% on idle.
2. Open a Firefox tab to app.element.io (with your user account logged in etc.)
3. Optional(?): pin the tab containing Element
4. Switch back to the other tab (ex: this github ticket) in Firefox, so that the Element tab is only in the background
### Outcome
#### What happened?
Constant 5 to 15% CPU usage (when not dividing CPU usage by the number of vCores, i.e. "not Solaris mode").
This was observed while idling in front of my laptop computer, with:
* General system monitor apps (ex: Astra Monitor, GNOME System Monitor, etc.) configured to not divide your CPU usage by the number of vCores, monitor the your CPU usage (and battery life)
* observing the CPU temperatures/fan speeds that never go down on a modern CPU
* Observing the output of about:performance in Firefox:

My laptop computer has a fairly recent power-efficient Intel Kabylake i5-8350U CPU that normally sits around 37-40°C with the fan turned off completely when nothing is using the CPU (so that it can enter deep sleep states). When I _don't_ have the Element web app tab open, it happily goes back down to 0% CPU usage and lower temperatures with the fan turning off entirely.
If I leave the app.element.io tab open in the background, temperatures always remain roughly 5 to 10°C higher _with_ the fan running indefinitely, and Firefox being the thing using CPU:

This happens even when the browser is minimized, on another workspace, etc. (but that is not so surprising to me at this point… because if it can waste CPU even when not the active tab, then it's certainly not a graphical thing, and more of a background waste independent from animations/widgets/views/etc.)
FWIW, my account is present in roughly 55 rooms, at least half (if not 70% or more) are mostly idle or fairly quiet, I'm not on super-busy rooms in general, and I'm not in thousands of rooms.
#### What did you expect?
0 to 1% CPU usage, "maybe" occasional tiny spikes once per minute or something.
Does Element stop anything non-essential (i.e. mostly anything that is not push notifications and updating its favicon) when it is backgrounded? If it can't, could it heavily throttle itself so that it doesn't poll/refresh/etc. as frequently?
Based on my understanding of post-Sandybridge CPU power saving features, you really want to let the CPUs sleep as much as possible; the current situation seems like a big drain on battery life.
### Operating system
Fedora 41
### Browser information
Firefox 137.0
### URL for webapp
app.element.io
### Application version
_No response_
### Homeserver
matrix.org
### Will you send logs?
No
Contributor guide
Assessment
This issue has not been assessed yet.