Jelmerro / Vieb

Vim Inspired Electron Browser - Vim bindings for the web by design
https://vieb.dev
GNU General Public License v3.0
1.29k stars 61 forks source link

Youtube player performance degradation #514

Closed KunaPrime closed 9 months ago

KunaPrime commented 10 months ago

Checklist

Describe the bug Severe performance degradation of YouTube player. When playing video there is noticeable lag in player interface as well as transition form an to full screen mode. It is getting worse as time progresses and with number of videos played. Degradation includes slow video playback sometimes.

To Reproduce Use Vieb 10..

Expected behavior on Vieb 9.. these problems where not observed, so it is expected not to be observed on versions >10.. also

Specs

Jelmerro commented 10 months ago

So in general these would be the steps I would try/recommend:

If all else fails I would really recommend to consider a proxy like Invidious or similar to not use Youtube directly, but that's of course not a solution to your problem, just a general recommendation.

KunaPrime commented 10 months ago

Thank you for suggestions, just to make sure we are in the same page i'm using Vieb both on Xorg and Wayland (Ubuntu and Fedora respectively), and these are my findings:

Jelmerro commented 10 months ago

Thanks for the quick response, the main difference that will be related to video playback would be the used Electron version and thus the Chromium version. The difference between 9.7.1 and 10.3.0 means Chromium 110 and 118, which means a lot has changed in the browser internals too.

If you want to absolutely make sure where the issue is, you could do the following to build Vieb (also see #building in the readme):

After doing so and giving me the list of results per version we can either:

Please let me know the results so I can further pinpoint where/why happening exactly.

Jelmerro commented 10 months ago

And yes, recordings of the performance of both versions of both the Vieb process and the page devtools would make it very clear if this is Youtube using a ton of CPU/computation power or a Vieb process that is working at something.

KunaPrime commented 10 months ago

just a quick question, to compare i have built 9.7.1 but (F8) is not opening dev tools for Vieb is there any other way how to access it or it was introduced in later versions?

Jelmerro commented 10 months ago

The default mapping is fairly recent, but on older Vieb versions you can open it with :internaldevtools.

KunaPrime commented 10 months ago

perfect

also i'm trying to record fairly consistent scenario of around 20 seconds and recording are about 10-30 MB each, what would be preferred method for me to send them your way?

Jelmerro commented 10 months ago

The filesize limit is 25MB on github, so that might work if you zip/7z them individually, but otherwise just via Telegram or Matrix works. Do keep in mind that I would really like to hear the result of trying current Vieb code with older Electron/Chromium versions to make sure it's not just a Chromium performance degradation, as per instructions above, you might get some startup errors due to missing APIs, but that's just for handling the custom viewer protocols such as the markdownviewer.

KunaPrime commented 10 months ago

ok, i'm having embarrassing issue now: electron versions 25 and above are not letting me save the performance timeline with and error: Failed to save timeline: The request is not allowed by the user agent or the platform in the current context. (NotAllowedError)

i'm tring to do as close as possible scenario each run:

in testing with clean (dev) profile problem was there but less pronounced but in any case my feeling is still that vieb > 10 has a problem. so far i was able to get this telemetry (<Vieb version>-<c|v>-<electron version>, where c is chromium tools and v is vieb tools):

9.7.1-c-23.2.zip 9.7.1-v-23.2.zip 10.3.0.-c-23.2.4.zip 10.3.0.-c-23.3.13.zip 10.3.0.-c-24.8.2.zip 10.3.0.-v-23.2.4.zip 10.3.0.-v-23.3.13.zip 10.3.0.-v-24.8.2.zip

i was also able to build Vieb 7.9.1 with electron 26.1 and problem was also not present.

in the process i have tried to isolate as much variables as i could but also i have few more ideas to try, one of which is having multiple youtube tabs and seeing if that has any effect on performance. That is next i want to try and i will report back.

Jelmerro commented 10 months ago

If it turns out to be more related to Vieb's code for some odd reason, you could try to find the commit that caused this by running git reset HEAD~ && git checkout . and then running npm run dev again, this will revert a commit and clean the unstaged changes, one commit at a time. You can also specify a number after HEAD~ like HEAD~4 to do multiple commits at once. I'm btw asking all of this of you, because I don't have a slowdown on Youtube pages myself in 10.3.0, so I sadly need you to find the problematic change that caused this. Thanks for taking the time to do this!

KunaPrime commented 10 months ago

Don't worry i'm happy to help any way i can, Vieb is perfect fit for me and i am daily driving it for almost 2 years now. Also i'm also dev but completely unexperienced in electron so it's bit hard to me to diagnose it directly. If we find that it is vieb code that's making things worse i have plan to do a "binary hunt" for the exact commit but for now i'm trying to establish where in general is the problem.

do you have any ideas as to why electron 25 and above is not allowing me to save telemetry/timeline? is is creating the file but then seems to not be able to access it.

KunaPrime commented 10 months ago

turns out that performance is changing exactly after final 9.7.1 commit. that is commit fd910e0069e742c978723995400ae813a041286f introduces issues for me. Reading commit i suspected that it is related to adblocker so i set it to off and it seems to completely solved the problem and i don't experience any lag what so ever.

Most reliable that i found how to test that is to play some video and then toggle full screen on and off. When adblocker is on, on versions greater than 9.7.1, some lag is accumulating slowly and in some circumstances that i'm not able to reliably repeat UI of player becomes so laggy that it is almost unusable. When adblocker is off there is no perceived lag accumulation and i'm yet to experience any degradation.

Turning off adblocking is not a great solution, so i tried to build Vieb with default ublockfilters.txt empty. That seem to have no affect on my issue but i need to do further testing.

Jelmerro commented 10 months ago

Very interesting that it turns out to be the adblocker. Vieb uses an external package for this, see https://github.com/ghostery/adblocker/tree/master/packages/adblocker-electron. You can change the filter lists using the docs explained at :help adblocker, in short, set it to custom and then edit the lists in <datafolder>/blocklists directly. You can remove them all, and with the custom setting, they will not be added back, so you can then add them one by one and see which list is the problematic one.

KunaPrime commented 10 months ago

great, i was reading doc for adblocker but it was not clear to me that with custom option i could persist changes to blocklists, i will try to isolate it further this weekend and report back as i think it would be useful information to know where the problem is exactly. Thanks for the pointer.

mfatiga commented 10 months ago

This issue also happens to me, I can also confirm that disabling adblocker fixes it.

Jelmerro commented 10 months ago

Can you reproduce this in the following project, and if not, can you reproduce it there if you update to a newer Electron as described above? Also make sure to try multiple instances and do monitor the CPU usage. https://github.com/ghostery/adblocker/tree/master/packages/adblocker-electron-example

KunaPrime commented 10 months ago

i can reproduce it in that project also and the problem is even more pronounced there if anything. Compared with Vieb with adblocker=off cpu usage is about 50% up if not more, but that's hard to measure.

Jelmerro commented 10 months ago

In that case, it's not a Vieb issue, and it would seem the commit that caused it is already known, as someone just opened a nearly identical issue in their repo also on youtube: https://github.com/ghostery/adblocker/issues/3420

KunaPrime commented 10 months ago

i'm glad that source of the problem is identified. At least now i can track that issue on adblocker's side. @Jelmerro thank you for your assistance and great work on this browser! (i think we can close this issue now)

Jelmerro commented 10 months ago

I'll keep it open for visibility until there is a new stable Vieb version that contains a non-laggy adblocker, because until then this issue is not solved in Vieb either.

Jelmerro commented 9 months ago

I converted the changes from the PR to patch files, which you can download and store inside an up-to-date Vieb repo inside the patches folder, then run npm ci and npx patch-package. You should now be able to test the new fixes from the adblocker project inside Vieb. Let me know if this fixes the performance issues. I might need to adjust some listeners too before cosmetic filtering works again, but the important part for now would be the performance. You can if you want to also let them know in the PR in their repo if this fixes the issue: https://github.com/ghostery/adblocker/pull/3441 as they asked me to have a look, but I don't have the performance issue you describe, so I'll need someone who does to test this fix.

KunaPrime commented 9 months ago

i have patched (per your instructions) Vieb against latest commit and performance is once again great! I also did a test without patch side by side and i see significant difference so i would say that this patch is solution at least for me.

Jelmerro commented 9 months ago

Great, thanks for the quick response, I'll let them know that this seems to have fixed the issue.

Jelmerro commented 9 months ago

Fixed in 10.4.0 :tada: