playcanvas / playcanvas/engine

game-pads.js allocates a new array every frame

Open
#842 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area: input enhancement good first issue
Dominant language
JavaScript
Stars
16.8k
Forks
2k
Avg merge
4h 32m
Merged PRs (30d)
222

Description

        update: function (dt) {
            var pads = this.poll();

            var i, len = pads.length;
            for (i = 0;i < len; i++) {
                this.previous[i] = this.current[i];
                this.current[i] = pads[i];
            }
        },
        poll: function () {
            var pads = [];
            if (this.gamepadsSupported) {
                var padDevices = navigator.getGamepads ? navigator.getGamepads() : navigator.webkitGetGamepads();
                var i, len = padDevices.length;
                for (i = 0; i < len; i++) {
                    if (padDevices[i]) {
                        pads.push({
                            map: this.getMap(padDevices[i]),
                            pad: padDevices[i]
                        });
                    }
                }
            }
            return pads;
        },

When poll() gets called, it allocates a new array to store the current gamepad state.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in game-pads.js at the update() and poll() entry points shown in the issue, and inspect how gamepad state is stored between frames. Verify the per-frame allocation with the relevant runtime profiling or existing gamepad tests; done means polling preserves current and previous state without allocating a new array on each call.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
game-dev, performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.