Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global plugins cause significant CPU usage #1275

Open
williamvds opened this issue Dec 29, 2023 · 6 comments
Open

Global plugins cause significant CPU usage #1275

williamvds opened this issue Dec 29, 2023 · 6 comments

Comments

@williamvds
Copy link

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

$('img[src*="nicoseiga.jp/thumb/"]:not(.hoverZoomMouseover), a[href*="/seiga/im"]:not(.hoverZoomMouseover)').filter(function() { if(/nico.*\.jp/.test($(this).prop('src'))) return true; if(/nico.*\.jp/.test($(this).prop('href'))) return true; return false; }).addClass('hoverZoomMouseover').one('mouseover', function() {

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?

@extesy
Copy link
Owner

extesy commented Dec 31, 2023

@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?

GrosPoulet added a commit to GrosPoulet/hoverzoom that referenced this issue Jan 1, 2024
GrosPoulet added a commit that referenced this issue Jan 1, 2024
Improvement for plug-in: niconico_a (#1275)
@GrosPoulet
Copy link
Collaborator

@williamvds @extesy #1276 should improve things.

@extesy
Copy link
Owner

extesy commented Feb 16, 2024

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

@williamvds
Copy link
Author

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.

@thunfischbrot
Copy link

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

@williamvds
Copy link
Author

@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'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants