hoverzoom icon indicating copy to clipboard operation
hoverzoom copied to clipboard

Global plugins cause significant CPU usage

Open williamvds opened this issue 1 year ago • 6 comments

Describe the bug

Global plugins cause significant CPU usage when loading pages with lots of matched elements, particularly <a> links.

This appears to be due to matching elements overzealously with loose patterns.

To Reproduce

  1. Enable hoverzoom with all global plugins

  2. Visit a site with a lot of elements, e.g. https://nix-community.github.io/home-manager/options.xhtml

  3. Observe slowdowns, and probably a warning from your browser about hoverzoom slowing down the page

Expected behavior

Loading large pages with hoverzoom enabled does not slow down the browser.

Screenshots

I profiled the page linked above on Firefox, with all the hoverzoom plugins enabled:

Profiling results with all plugins enabled

image

I then disabled most of the global plugins I could find, particularly the most expensive ones in the above image. Profiling again, I see lower CPU usage, but the enabled plugins now appear to run twice?

Profiling results with some global plugins disabled

image

Desktop (please complete the following information):

  • OS: GNU/Linux
  • Browser: Firefox
  • Version: 121

Additional context

The profiling suggests the JQuery selectors are the most expensive part of processing. E.g. the most expensive matcher here

https://github.com/extesy/hoverzoom/blob/acccb87b2841624b6f5b4fd228152d795d3adbe1/plugins/niconico_a.js#L24

Is performing fuzzy matching on every link and image on every page.

image

Could these be prefix matchers instead, e.g. img[src^="https://lohas.nicoseiga.jp/thumb/"]? I couldn't quite work out what the URL should be for niconico, comments in the plugin suggest you need an account to view some pages.

Would document.querySelectorAll be faster than JQuery?

williamvds avatar Dec 29 '23 17:12 williamvds

@GrosPoulet You added this plugin ("niconico_a.js") - does it have to be a global plugin, can it be scoped to a smaller subset of sites?

extesy avatar Dec 31 '23 16:12 extesy

@williamvds @extesy #1276 should improve things.

GrosPoulet avatar Jan 01 '24 18:01 GrosPoulet

@williamvds Can you please confirm if this is still a problem in version 1.0.214.2?

extesy avatar Feb 16 '24 02:02 extesy

image 1.0.214.2 shows significant improvement with the niconico plugin specifically. Hoverzoom still locks up on the page in question, because all the global plugins add up.

For now I'll keep global plugins disabled, there isn't really any other workaround.

williamvds avatar Feb 18 '24 14:02 williamvds

Is there a way to identify global plugins from the hoverzoom+ UI, in order to deactivate them in one go?

thunfischbrot avatar Apr 18 '24 13:04 thunfischbrot

@thunfischbrot The plugins with the _a suffix are the global ones.

I had to disable them with some javascript in the console while on the settings page (for me that's moz-extension://effe954f-ff0e-4b40-bc2c-4dda6eff4348/html/options.html)

Array.from(document.querySelectorAll('input[type="checkbox"][id*="_a"]')).forEach(e => $(e).trigger('gumby.uncheck'))

williamvds avatar Apr 18 '24 17:04 williamvds