8bitdna

UWP Hosted Apps / Edge Stuttering

Recommended Posts

Hi All,

Any game I run in Edge or UWP hosted apps has a horrible frame drop every few seconds.  This is specifically when using the Panda 2 Gamepad plugin and looks like its down the button state management in the plugin and Edge probably requesting button state each time and it being slow.  This code...

                for (var i = 0; i < gamepad.buttons.length; i++) {
                    if (gamepad.buttons[i].pressed && !pad.buttons[i].pressed) {
                        this.pressed(i, gamepad.index);
                    }
                    else if (!gamepad.buttons[i].pressed && pad.buttons[i].pressed) {
                        this.released(i, gamepad.index);
                    }
                    pad.buttons[i].pressed = gamepad.buttons[i].pressed;
                }

I've improved things a lot by taking a copy of the state and working with that like this by adjusting the plugin code like this...

                var clone = gamepad.buttons.slice(0);
                for (var i = 0; i < clone.length; i++) {
                    if (clone[i].pressed && !pad.buttons[i].pressed) {
                        this.pressed(i, gamepad.index);
                    }
                    else if (!clone[i].pressed && pad.buttons[i].pressed) {
                        this.released(i, gamepad.index);
                    }
                    pad.buttons[i].pressed = clone[i].pressed;
                }

I still see a little frame drop (not as bad) every few seconds though on Edge and UWP hosted apps.  This is running the Gamepad plugin example with no changes other then the above.  Tried a bunch of random HTML5 games on the interwebs and they all seem ok, any ideas?

Share this post


Link to post
Share on other sites

That's really strange. In your code change, you are creating new array each frame with the slice function, which should make everything even worse (since you are creating garbage). There must be something else that is slowing your game down.

Does this happen on desktop Edge too?

Share this post


Link to post
Share on other sites

Yep, new array every frame and yes happens on desktop Edge.  Try out your Gamepad Plugin example on Edge with an Xbox controller if possible, you should see the 'janking'.  Then change the code to what I did and you'll see it improve but then get little frame rate drops, that could be the garbage collection though from the new array etc.  I'm no JS expert, is there a way to create an array once and copy the contents of gamepad.buttons into it every frame so we don't create the garbage?  I think every time you look into the gamepad.buttons[x].pressed prop it triggers a request at the hardware for ALL buttons state with edge, so as you iterate around the loop its slow, thats the only explanation I could think of!  Shouldn't be like that though according to the official Gamepad HTML5 spec, looks more like an Edge bug.

Share this post


Link to post
Share on other sites

Seems that way.  Take your Gamepad example and run in on the Xbox or Edge, you'll see the janking.  Then remove this code from you Gamepad plugin and try again, janking gone..

                for (var i = 0; i < gamepad.buttons.length; i++) {
                    if (gamepad.buttons[i].pressed && !pad.buttons[i].pressed) {
                        this.pressed(i, gamepad.index);
                    }
                    else if (!gamepad.buttons[i].pressed && pad.buttons[i].pressed) {
                        this.released(i, gamepad.index);
                    }
                    pad.buttons[i].pressed = gamepad.buttons[i].pressed;
                }

An looking at that code I can't believe it has a significant impact on performance hence why I was thinking Edge issue, see what I mean?  I'm not that much if a JS expert to profile it properly etc, maybe its something else but the Gamepad example hardly does anything (in terms of resource hungry things and a need for performance) so it seems a coincidence.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.