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

[Bug] Installed style causes Stylus to freeze on Firefox #1590

Open
srichter opened this issue Apr 27, 2023 · 10 comments
Open

[Bug] Installed style causes Stylus to freeze on Firefox #1590

srichter opened this issue Apr 27, 2023 · 10 comments
Labels

Comments

@srichter
Copy link

srichter commented Apr 27, 2023

Bug Report

Bug Description

The Google Darkest Fusion style causes Stylus to constantly freeze when it is installed in Firefox. This also causes all network requests in the browser to become stuck while the extension is frozen. It doesn't matter if the style is enabled or not, just having it installed causes the issues. The style manage page locks up, as well as the extension popup on various sites (such as a twitch.tv stream page) when the style is installed. I noticed the issues and isolated the problem to this style in a new browser profile with only Stylus and that style installed. The second the style is installed you can observe the issues.

Screenshots

CSS Code

System Information

  • OS: macOS
  • Browser: Firefox 112.0.2
  • Stylus Version: 1.5.30

Additional Context

I haven't been able to figure out anything consistent between pages where the issue occurs, but it may be pages which have a large number of images (such as a twitch.tv chat). When the extension popup freezes it eventually will display, but in a broken state.
Screen Shot 2023-04-27 at 16 41 47

@tophf
Copy link
Member

tophf commented Apr 27, 2023

I can't replicate the problem. Please use Firefox profiler to capture the log. The log can be uploaded when suggested by the profiler so you can share the link here or you can analyze it yourself.

@srichter
Copy link
Author

Here's a profile https://share.firefox.dev/3LemTfV

@tophf
Copy link
Member

tophf commented Apr 27, 2023

Looks like this userstyle has so-called "catastrophic backtracking regexps" that only activate on some URLs. Unfortunately we can't fix the extension, so you or someone else (the author of the userstyle) will have to find and fix these expressions. See also #416.

@srichter
Copy link
Author

I had a hunch it was regexp related (even before the profile) since that style has so many complex ones. I'll see if I can isolate which one it is and attempt to fix it (and let the author know).

The behavior still occurs when the style is disabled, which likely caused false-negatives when I've investigated this in the past (thinking that this style wasn't the cause since it was "disabled" and the problem still occurred). Is that an issue with Stylus where it's still checking regexps when a style is disabled?

@tophf
Copy link
Member

tophf commented Apr 27, 2023

The last section looks particularly suspicious because it uses ?! negative lookahead.

@tophf
Copy link
Member

tophf commented Apr 27, 2023

Is that an issue with Stylus where it's still checking regexps when a style is disabled?

Normally it should happen only when showing the styles in the popup. I'll check if that's so...

Edit: turns out it wasn't, so I'll fix it.

@srichter
Copy link
Author

srichter commented Apr 27, 2023

Looks like it's https:\/\/(www\.)?([\w]+|-+)*\.translate\.goog\/.* which is causing the issues on twitch.tv. Removing this regexp eliminates the issue. I'll let the style author know. Appreciate you taking a look

Would it be possible for Stylus to detect these long-running regexps and show a warning or otherwise aid in their detection? It took me quite a while to narrow down the Firefox freezing issues to Stylus, then to that specific style.

tophf added a commit that referenced this issue Apr 27, 2023
@tophf
Copy link
Member

tophf commented Apr 27, 2023

Try replacing ([\w]+|-+) with \w+(-\w+)*

@tophf
Copy link
Member

tophf commented Apr 27, 2023

Would it be possible for Stylus to detect these long-running regexps and show a warning or otherwise aid in their detection?

Adding such instrumentation isn't free so I don't think we can measure each regexp, but I guess we can check the overall matching time and warn somehow, but it's not easy either.

It took me quite a while to narrow down the Firefox freezing issues to Stylus, then to that specific style.

Now you know you can do it quickly by using Firefox Profiler :-)

@srichter
Copy link
Author

That seemed to fix it. I'll pass it along to the style author.

Adding such instrumentation isn't free so I don't think we can measure each regexp, but I guess we can check the overall matching time and warn somehow, but it's not easy either.

Perhaps it's something Firefox should be warning about (an extension regularly locking for 6+ seconds)

Now you know you can do it quickly by using Firefox Profiler :-)

Definitely! This tool seems invaluable for diagnosing issues

@tophf tophf removed the help wanted label May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants