gdx-controllers
gdx-controllers copied to clipboard
Reduce garbage produced every update
Hi, after some profiling found that this library produces quite some garbage every frame/update.
- so what I did is to cache
ControllerButton.values()andControllerAxis.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 newFloats 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.
Forgot about this one, sorry, but finally made the changes.