gdx-controllers icon indicating copy to clipboard operation
gdx-controllers copied to clipboard

Reduce garbage produced every update

Open klianc09 opened this issue 2 years ago • 1 comments

Hi, after some profiling found that this library produces quite some garbage every frame/update.

  • so what I did is to cache ControllerButton.values() and ControllerAxis.values() for the update methods, since those were creating new arrays all the time. (some JVMs might be able to correctly optimize this, but the one I profiled did not)
  • also the line axisState.put(id, value); was causing the values to be boxed to new Floats every update, so I introduced a simple wrapper class with a mutable float, which does not create any garbage

This only covers the desktop version, similar optimizations could be made for other platforms probably.

IDK if this can be merged as-is, but would love to hear about any suggestions or doubts.

klianc09 avatar Jun 24 '23 13:06 klianc09

Forgot about this one, sorry, but finally made the changes.

klianc09 avatar Dec 13 '23 10:12 klianc09