swarmsim / swarm

Swarm Simulator, an idle game with lots of bugs.
https://www.swarmsim.com
GNU General Public License v3.0
479 stars 140 forks source link

swarmsim.github.io is unresponsive #714

Open pts opened 6 years ago

pts commented 6 years ago

On Chrome 65 on Linux (Debian and also Ubuntu), after starting a new game and playing it for 8 minutes, swarmsim.github.io becomes unresponsive: several times in a minute the game pauses for 10 seconds, not updating the display, and not reacting to mouse clicks. The CPU usage goes up to 100%.

It's so unresponsive that it's imposible to enjoy the gameplay.

It works fine in Firefox 52 on the same system.

Salmela commented 6 years ago

I had the same issue that the game was hanging every few seconds. My chromium version is: 62.0.3202.89 (Developer Build) built on Debian buster/sid.

The issue that I captured was in the function Ia.toPower.Ia.pow @ vendor.c7818001.js:14 It once took 2.53 s of execution time and the whole page was frozen for that time.

I think it froze the browser, because it was called inside animationframe handler:

            e.prototype.requestAnimationFrame = function(a) {
                return window.requestAnimationFrame(function() {
                    return a(),
                    c.$digest() // < here
                })
            }

Here is the stacktrace:

0ms 0% 2530.2ms 100.0%      (anonymous) scripts.e2cd97c2.js:formatted:13856
0ms 0% 2530.2 ms 100.0%     $digest vendor.c7818001.js:formatted:4321
0ms 0% 2530.2 ms 100.0%     (anonymous) vendor.c7818001.js:formatted:3756
0ms 0% 2530.2 ms 100.0%     fn  VM154:4
0ms 0% 2530.2 ms 100.0%     d   scripts.e2cd97c2.js:formatted:11326
0ms 0 % 2530.2 ms100.0 %    value   vendor.c7818001.js:formatted:1
0ms 0 % 2530.2 ms100.0 %    g   vendor.c7818001.js:formatted:1
0 ms0 %2530.2 ms100.0 %     prefix  vendor.c7818001.js:formatted:62114
2527.9 ms 99.9% 2530.2ms 100.0 %    Ia.toPower.Ia.pow   vendor.c7818001.js:formatted:22475
0.4ms 0.0% 1.4ms 0.1%       n   vendor.c7818001.js:formatted:21130
0.3 ms 0.0% 0.9ms 0.0%      Ia.equals.Ia.eq vendor.c7818001.js:formatted:21847

I tried to debug the obfuscated more code, but that was not successful. Only thing that I figured out was that the Decimal().toPower function came from decimal.js. And that the toPower function is causing lag at multiple places of the vendor.js code. I noticed this from the performance tab.