hoverzoom
hoverzoom copied to clipboard
Global plugins cause significant CPU usage
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
-
Enable hoverzoom with all global plugins
-
Visit a site with a lot of elements, e.g. https://nix-community.github.io/home-manager/options.xhtml
-
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
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
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.
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?
@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?
@williamvds @extesy #1276 should improve things.
@williamvds Can you please confirm if this is still a problem in version 1.0.214.2
?
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.
Is there a way to identify global plugins from the hoverzoom+ UI, in order to deactivate them in one go?
@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'))