Tampermonkey / tampermonkey

Tampermonkey is the most popular userscript manager, with over 10 million users. It's available for Chrome, Microsoft Edge, Safari, Opera Next, and Firefox.
GNU General Public License v3.0
4.15k stars 415 forks source link

Script page load slow down messages persists even after the script is loaded #1187

Open dnknn opened 3 years ago

dnknn commented 3 years ago

Sys: Win10、 Chromium80-89 (tested+verified) 、Tampermonkey all versions(stable&beta) (at least 1 year)

💥 2 fatal problems caused by using Tampermonkey as UserJS/scripts container :

  ①. On some pages, it will cause a significant performance drop (very high CPU-usage), and some even crash (it takes ⩾8s~90s to complete load ), during this period, other normal pages will also fail to open.   ②. On some pages, scripts cannot be excluded(// @exclude ) at all, even the script is disabled, and even delete to the trash/recycle-bin, still cannot be ruled out.

The above two problems should be directly related. can skip this floor and look directly at the test example below and the test comparison of Violentmonkey :

👉 https://github.com/Tampermonkey/tampermonkey/issues/1187#issuecomment-804521668 👉 https://github.com/Tampermonkey/tampermonkey/issues/1187#issuecomment-805264334 👉 https://github.com/Tampermonkey/tampermonkey/issues/1187#issuecomment-812256520

   

🗣 important statement:

sorry for my English..... and I don't know the code very well either, But the problem to be said below is indeed a very fatal problem,


💥 This fatal problem manifested as:

The root cause is: It is completely impossible to prevent the script from being executed on a certain page, so:


For example:

  1. Then I tried to exclude the script not working on this page, but the results are all invalid...

    *taobao*

image

213_22055350

  1. Yes, I also added the URL of the iframe, but still cannot be ruled out.

    /.*(?:aliapp|alibaba|alicdn|aliyun|aliyuncs|effirst|mmstat|tbcdn).+/

  2. So I tried to disable/OFF the script, but it still doesn't work.

  3. Finally, I even tried to delete the script and temporarily put it in the 🗑Recycle Bin (beta version). Even if I delete it to the Recycle Bin, the script is still working... 1


After recording, I intentionally reduced the size of the gif (too big)

gif22

Therefore, I think it is not a script code problem (I encounter a very simple code that does not have any problems also have this problem), so this is completely a bug in the Tampermonkey container.


@derjanb I have sent the configuration of Tampermonkey and 100+ scripts to your 📧mail. You can reproduce the problem in 5 minutes.

  1. Import the Tampermonkey script. (30 seconds)
  2. Open several sample URL pages provided. (The problem can be reproduced immediately)   You will find that the page can hardly be opened, and the CPU usage is very high, (Tampermonkey's own page also froze and couldn't be opened.)
  3. Hope can investigate this problem carefully. When you encounter this fatal problem, there is currently no any way except to disable the Tampermonkey extension... so hope to fix this problem first.

Finally, the test content:

Why does it cause a significant drop in performance? What is terrible is that it is impossible to exclude scripts for such pages.

  1. Why is the script of the page excluded, even after the script is deleted to the recycle bin, the script is still executed in the background?

  2. Why the script code itself has no problem, but it will cause performance crash on some pages, why? Because I used Violentmonkey for the same test, there is no such performance problem and the problem that cannot be eliminated.

dnknn commented 3 years ago

Supplementary comparison testing video :

🗣 Using Violentmonkey as the script container, there is no problem, which means that there is no problem with the script code.

⚔ Page performance test video of Violentmonkey : hardly any impact.

Even if I export more than 100 scripts from Tampermonkey and then import them to Violentmonkey, after testing, Violentmonkey has almost no impact on the performance of the page.

Violentmonkey   With 3 scripts enabled, there is almost no impact on performance, and the loading completion time is only 0.3s longer (1.25s -> 1.55s)


@derjanb Under the same test environment, use Tampermonkey as a script container, Tampermonkey will cause page performance crash, high CPU usage, Once encounter a page like this that causes performance, all pages cannot respond to network requests, and the page cannot be opened in a short time.

⚔ Page performance test video of Tampermonkey : fatal impact -_-

⚠: The test here only installs 3 scripts, and the speed affects 2s (1.25s -> 3.1s). If the user installs ⩾ dozens of scripts (but not enabled), it will take at least 30s to respond at this time, and the page will crash during the period, and other pages will not be opened. .

 

Tampermonkey

 

So I hope that the most deadly root cause can be investigated, and it can be perfectly fixed!

dnknn commented 3 years ago

I even forgot, recommend a perfect open source & lightweight extension, a very useful/convenient testing tool:

This time value is consistent with the time in DevTools.

Test/comparison page

image


🗣 It can be seen that Violentmonkey has almost no negative influence/effects👇!

The same test environment, the same number of scripts and the number of runs.

image

I hope to find out the root cause of Tampermonkey's performance degradation and finally fix this problem. Thank you very much!!!

dnknn commented 3 years ago

@derjanb Hello!

derjanb commented 3 years ago

Should be fixed at the latest BETA version which will be published at the Chrome Web Store after review.

dnknn commented 3 years ago

Should be fixed at the latest BETA version

@derjanb First, thanks very much for your contribution in the fixed works, when I saw your reply message, I was very happy, I also looked at the update log. But.....no...no......no.... I was disappointed after the test...this very very fatal/serious problems still exist... Please see picture below, it is very intuitive to see the severity/fatality of the problem.

214_02081745

The original speed of this page is actually ⩽1s when opened under the cache, before, under DevTools \<Network> opened , it will affect about 0.3s.

From the perspective of page completion time alone, from 1.0s to 21s, this problem is very serious. For comparison, Violentmonkey's time is 1.3s (extending 300ms is normal) (working 10 of 200 UserJS ).

ps: Violentmonkey's time may also be 1.1s or 1.2s (I did not test Violentmonkey again this time, but was a complete test before.) so obviously the UserJS code itself has no performance issues.

Test / Demo :

⚠Please Note⚠: You must be enough scripts (dozens or ≋ 200) to reproduce the problem.

1) Helper/assistant:  Page load time chrome.google.com/webstore/ (very convenient to view page/DOM time)

2) Test page:   https://item.taobao.com/item.htm?id=602809430649

ps: This page is the most influential page I know, 21s, so it is the best test sample. There are also many other pages that will be affected by performance, but it may be extended by about 3s, 5s, or 10s.

3) You must be enough scripts (e.g. dozens or ≋ 200) to reproduce the problem (You can find the 100 scripts I sent you before in your mailbox)

4) Reproduce this 21s fatal performance problem.....-_-

⚠⚠Please Note⚠⚠: You must be enough scripts (dozens or ≋ 200) to reproduce the problem.

The latest version seems to have improved a little: if it is the above 3 UserJS, the page time is ≋2.2s, but it extended by 1.2s, which is obviously problematic. But if your Tampermonkey has a sufficient number of scripts, then this time impact will be significantly extended, such as 21s !!! -_-

PS: personal point of view: the features of Tampermonkey is already very powerful, so I think the focus of works should be on the direction of improving performance.


Expected time: ⩽1.5 at most (i.e. 1.0s->1.5s)

sorry for my English.......I don't know if you can understand the meaning....


In addition, the scripts cannot be really excluded (e.g. // @exclude) of bugs, I haven't tested it carefully, if there are any problems, I will tell you.

dnknn commented 3 years ago

Hi, @derjanb !

  • I have encountered this serious problem on quite a few pages: the opening is slow, or even almost impossible to open, which makes me very sad. Even if UserJS is not enabled or only three or two are enabled on these pages, it is still the same problem. If I disable Tampermonkey or using Violentmonkey, the page opens successfully in an instant.
derjanb commented 3 years ago

Yes, this message persists for 5 minutes even if the script is deleted in the meantime. However, the script is not executed or even considered for execution anymore.

So yes, there is a problem, but only a cosmetic one.

dnknn commented 3 years ago

@derjanb I guess that the fatal problem of this issue may be related to this problem 👇 ?

// @include     /(?:greasyfork|sleazyfork).org/.*/
// @include     /.*greasyfork.org.*/
// @include     /greasyfork.org/
// @noframes
        ❌ invalid 
// @exclude     *reg.163.com/*
// @exclude     *mail.163.com/*
        ❌ invalid 

In the end, it still prompts that the script has been executed 6 times

This code can quickly copy the URLs of all iframes embedded in the top page

// Copy all iframeURL
let ifrSrc = [];
top.document.querySelectorAll(`iframe:not([src='about:blank'])`).forEach(fE =>{
ifrSrc.push(fE.src);
});
ifrSrc=Array.from(new Set(ifrSrc));
copy(ifrSrc.join(`\n`)+`\n`); console.log(`✔️copied: `+ifrSrc.length +`  iframeURLs`);
derjanb commented 1 month ago

Should be fixed at 5.3.6205 (crx|xpi in review)

Please download the crx file linked above and drag and drop it to the extensions page chrome://extensions (after you've enabled 'Developer Mode').

For a quick fix please export your settings and scripts as zip or (JSON) file at the "Utilities" tab and import it back at the fixed BETA version.