conceptualspace / yet-another-speed-dial

a modern speed dial for chrome, edge and firefox
Other
177 stars 32 forks source link

High CPU usage #13

Closed Darthagnon closed 4 years ago

Darthagnon commented 4 years ago

Checking the CPU usage of this extension in the Chromium/Edge task managers shows constant CPU usage while a Speed Dial tab is open (for me, i7-7700HQ, it cycles between 1.6 and 12.7 in the browser task manager - NB this is not equivalent to real CPU usage, eg. in Windows Task Manager, afaik).

Compare this with 0% CPU in the browser task manager for Toolbar Dial, an almost-identical Speed Dial extension, on the same browser, under the same conditions. (NB it already features "choosing which folder to use as Speed Dial", which YASD lacks).

What is YASD using all that CPU for?

conceptualspace commented 4 years ago

that's odd, will try to reproduce. typically the only thing yasd does that could be considered cpu intensive is when you upload a custom image as a thumbnail, it resizes the image. but that would only be a transient spike (happens in milliseconds) not continuous. what version of chrome and yasd are you running exactly?

Darthagnon commented 4 years ago

Here's a screenshot, showing typical behaviour (its CPU usage seems to cycle up and down every few seconds)

I'm using M$ Edgium 84.0.522.5 (Official build) dev (64-bit) (latest dev version); latest version of YASD from the Chrome Web Store. Identical behaviour observed in old Ungoogled Chromium v70, and in an older build of Edgium from a few weeks ago, when I first tried the extension.

conceptualspace commented 4 years ago

got it. should only occur when the tab is in focus, right? background tab usage goes to 0?

it's likely result of the animation ticker. this allows the speed dials to animate smoothly when certain events occur, like resizing the window or dragging a tile. it runs on spare cpu cycles so shouldn't be considered expensive, but it keeps everything a buttery 60fps.

Technical explanation:

"The ticker is driven by requestAnimationFrame events in modern browsers so that the updates are perfectly synchronized with the browser's rendering cycle. It also means that when the user switches to a different tab in the browser, the ticker's updates get throttled back significantly in order to conserve battery power and reduce load on the CPU (this happens because the browser itself throttles back requestAnimationFrame event dispatching). Typically requestAnimationFrame events occur around 60 times per second, but that's up to the browser and depends on system performance as well. If requestAnimationFrame isn't supported, the ticker automatically falls back to using a regular setTimeout() loop which is supported in all browsers."

hope that answers your questions. the relevant piece of code is the animate function in index.js. cheers

conceptualspace commented 4 years ago

just noting for posterity: actual cpu usage on my test system with an active yasd tab open is < 1%

Darthagnon commented 4 years ago

Toolbar Dial has 0% CPU usage in the browser task manager whether focused or unfocused - it's a similar extension with a few more features; perhaps the code might provide some ideas? I tested YASD again, it was 0% as long as not in focus. As soon as a YASD tab was in focus, in-browser task manager reported CPU jumping between 9%-14% (NB this does not translate directly to real Task Manager CPU usage; browser task manager seems to apply a scaling factor, perhaps as a percentage of the CPU used by the browser?)

conceptualspace commented 2 years ago

replaced the ticker with more efficient code in 16f005afe5b13a681b4582e6f53c0e4ae3348015

the usage will never be truly 0 because YASD animates the dials on window resizing; so it has to know when such resizing occurs. but the cost is very low

Darthagnon commented 4 months ago

High CPU usage is still an issue with this plugin.