haxball / haxball-issues

113 stars 42 forks source link

When Browser Window and Tab Are Not Shown, Headless Runs Very Slow #2136

Open kadavrahaxball opened 2 months ago

kadavrahaxball commented 2 months ago

In Chrome, Haxball Headless runs fine with its tab open and the room running. However, when I switch to a different tab, some things run very slowly. For instance, when I use setDiscProperties() within onGameTick, instead of running 60 times per second, the setDiscProperties() function runs only 2-3 times per second.

Everything runs fine when the Headless tab is open. Even when I bring it to the foreground as a window, it runs normally. But I can't hide the window or switch to another tab. Oddly, when I open Haxball Headless via VDS and don't connect with Remote Desktop, it also runs slowly. It speeds up to normal when connected with Remote Desktop.

I'm attaching videos of both the normal and slow states. Is this a bug or something I can resolve somehow? Hopefully, there's a solution to my issue.

https://github.com/haxball/haxball-issues/assets/128331759/1a3f411c-9cd1-4604-895e-1e1dca261abc

https://github.com/haxball/haxball-issues/assets/128331759/4d97d495-87e2-4588-9451-85e0e098bf9c

Dani-404 commented 2 months ago

Yes, Google Chrome nerf performances of setInterval() and requestAnimationFrame() when tabs are inactives. The only way to fix it, is using the haxball script in web workers services or let tabs active.

If you use puppetteer you can use headless "new" for keep performances.

rajsa6 commented 2 months ago

How did u set that line above ur head, and do u maybe know how to fix my problem if u didnt see check on my post. ty