how websites waste CPU cycles & battery and Firefox lets them
by h43z (hompage)
I recently got a new notebook and noticed that the speakers would occasionally emit a faint but annoying white noise. This issue was only noticeable in a quiet room when no music or other audio was playing through the speakers.
After some digging, I came across the following command
pactl list sinks short
(check powercfg /requests on windows?!)
This command lists all available audio sinks for PulseAudio on Linux along with their current state. The states can be one of the following: IDLE, SUSPENDED, or RUNNING.
I observed that the speakers remained silent whenever the audio sink was in the SUSPENDED state. However, the white noise would sometimes occur when the sink was in IDLE or RUNNING, even when no music or sounds were being played.
Even though I had the setting to automatically suspend the audio sinks after 10 seconds of inactivity:
% grep -R module-suspend-on-idle /etc/pulse/
/etc/pulse/default.pa:load-module module-suspend-on-idle
/etc/pulse/system.pa:load-module module-suspend-on-idle
But sometimes, the sink never went IDLE and therefore never got SUSPENDED.
The manual for module-suspend-on-idle says:
Since 0.9.11. Disconnects sinks and sources from their backend after a
predetermined amount of idle time. Idle time is accumulated when the sink/source
in question is not connected to any streams.
Advantages: Saves power. ALSA uses considerably more CPU cycles when pulseaudio
has to send empty data to the soundcard during idle. If you don't plan to have
an active stream all the time, set the timer to a low value for best power savings.
I began using the command:
pactl list sink-inputs
whenever I noticed the white noise, trying to identify which program was using the audio sink.
It turned out to always be Firefox. However, none of the open tabs were supposed to play any sound—not even muted videos.
To get behind what was going on, I created a small script for my i3 status bar. The script displays a red indicator whenever the audio sink switched to the RUNNING state.
The culprit seemed to be the notification sound from my pinned tab of outlook.office.com. Whenever I received an email, the white noise would start and wouldn’t stop until I reloaded the tab or restarted Firefox.
This issue was not just about the annoying white noise—it was also draining my notebook’s battery faster.
Here’s the CPU/power consumpti
6 Comments
martin_a
Should I be able to actually hear something?
Firefox 134.0.1 on MacOS here, I don't hear anything.
mike_d
The websites opening an audio context without using it to play anything are probably doing bot detection.
Different browser engines and operating systems implement audio processing differently, so if you play a completely inaudible sound and then record it back (from the API not the microphone) you end up with a signature.
You can use that signature to see if the browser is lying about its user agent, running in headless mode, or all sort of other interesting edge cases that are not a real user buying widgets.
https://github.com/fingerprintjs/fingerprintjs/blob/3201a7d6…
pianom4n
Wow, this white noise has been driving me crazy for a long time but I could never track it down.
The tab doesn't show the "playing" icon, and muting the tab doesn't stop the noise.
Even using the Windows volume mixer to mute Firefox doesn't stop the noise.
Edit: The addon is actually pretty bad for a desktop user since the white noise starting/stopping constantly is far more annoying.
cosmotic
If the output idles, digital SPDIF signals lose sync. Re-syncing once playback starts is not instant, and you lose the first second of audio or so. I wrote a program that kept open an output withought dumping any data to the line, just to prevent the output from idling.
Doesnt make much sense in the context of a laptop though, so energy savings make sense there.
padenot
This is planned, and important, and we'll fix it hopefully soon, it's long overdue. I'm sorry this hasn't happened yet, it's always a game of priorities that can never satisfy everybody on time. It however ranks fairly high on my personal list.
As one could imagine it's a bit (read: a lot) more complicated than just pausing the AudioContext after some time of silence, but we'll get it fixed regardless, it's possible because others did it. There are tradeoffs we're willing to do.
Source: Firefox implementer of a lot of things around this, editor of the Web Audio API standard.
unit149
[dead]