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

Youtube player performance degradation #514

Closed
4 tasks done
KunaPrime opened this issue Aug 31, 2023 · 24 comments
Closed
4 tasks done

Youtube player performance degradation #514

KunaPrime opened this issue Aug 31, 2023 · 24 comments
Assignees
Labels
bug Something isn't working

Comments

@KunaPrime
Copy link

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

  • tested on Ubuntu 20.04.6 LTS (Xorg) and on Fedora 38 (Wayland)

  • Version: Vieb 10.3.0

@KunaPrime KunaPrime added the bug Something isn't working label Aug 31, 2023
@Jelmerro
Copy link
Owner

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

  • Make sure you are using the Wayland specific flags to improve performance, these are the same for other Electron apps, but usually these 2 are a good start: --enable-features=UseOzonePlatform --ozone-platform-hint=auto
  • Check the chrome://gpu page to see if hardware acceleration is enabled
  • Make sure to check if this is a Youtube-only issue (Google making it slow on purpose outside mainline Chrome wouldn't be the first time)
  • If it seems to be a general issue for video playback and there is hardware acceleration, please open the development tools of Vieb (using F8 instead of F12), and go to the performance tab, then make a recording of around 10 seconds, and do the same for the regular devtools (opened with F12), then send me the results here
  • If it's a Youtube only issue, is the performance suddenly better if you use the V9 releases? And if so, does the chrome://gpu page show different stats? What about other pages? The more we can narrow down this issue, the more likely it is to be solved.

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.

@Jelmerro Jelmerro added the question Further information is requested label Aug 31, 2023
@KunaPrime
Copy link
Author

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:

  • suggested flags: --enable-features=UseOzonePlatform --ozone-platform-hint=auto had no effect as I expected since problem is present on both Wayland and Xorg manifesting the same way.
  • hardware acceleration is enabled for both systems and also for both pre and post 10 versions of Vieb
  • it seems to be youtube only issue as other video platforms such as (vimeo, twitch and other video sources that are not Youtube) wok as expected, i have not noticed any issues other than connected with video on Youtube
  • it seems not to be general playback issue as stated above but i can still make performance recordings if You think it would be helpful, and also do You think if it would be useful to do recordings for both pre and post 10 releases?
  • It seem to be Youtube only issue, and chrome://gpu seems to have same status in 9.7.1 and 10.3.0 release. Other pages seems to be fine. Also i have just downgraded Vieb on Fedora/Wayland system to 9.7.1 and issue is gone!

@Jelmerro
Copy link
Owner

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):

  • Download/clone the repo
  • Go to the folder in a terminal
  • Run npm ci
  • Start with npm run dev for a separate instance or if you want to use your regular session do npm start
  • Check if the issue is present (it should be, because there have been no commits since making the 10.3.0 release)
  • Now install an older version of Electron and try again, current version is 27
    • First try 26: npm i electron@26 and check again with npm run dev or npm start, this version might show a blank screen, hence why I skipped 26 entirely for the releases
    • Next try 25: npm i electron@25 and again npm run dev or npm start and try to reproduce
    • Do the same for 24 and finally 23, which is the version that Vieb 9.7.1 is using

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

  • Pinpoint exactly which Electron/Chromium release caused this
  • The ozone flag that I added by default to 10.3.0 desktop releases could be having an effect it should not
  • Performance issues are only present in built versions (which you could try to do too using the instructions from the readme, but I'll explain that when/if it's needed)
  • Or if changing the Electron version doesn't make it work, we can conclude that I somehow did something wrong in the Vieb code to make this happen

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

@Jelmerro
Copy link
Owner

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
Copy link
Author

KunaPrime commented Aug 31, 2023

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
Copy link
Owner

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

@KunaPrime
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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:

  • play the video form the minute 1:00
  • go to the full screen (youtube full screen)
  • pause and then resume video
  • go back to normal view
    while waiting for all transitions to finish

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Author

turns out that performance is changing exactly after final 9.7.1 commit. that is commit fd910e0 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
Copy link
Owner

Jelmerro commented Sep 2, 2023

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
Copy link
Author

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
Copy link

mfatiga commented Sep 5, 2023

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

@Jelmerro
Copy link
Owner

Jelmerro commented Sep 5, 2023

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
Copy link
Author

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
Copy link
Owner

Jelmerro commented Sep 6, 2023

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: ghostery/adblocker#3420

@KunaPrime
Copy link
Author

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
Copy link
Owner

Jelmerro commented Sep 6, 2023

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
Copy link
Owner

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: ghostery/adblocker#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
Copy link
Author

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
Copy link
Owner

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

@Jelmerro Jelmerro self-assigned this Sep 18, 2023
@Jelmerro Jelmerro removed the question Further information is requested label Sep 18, 2023
@Jelmerro
Copy link
Owner

Fixed in 10.4.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants