Refactor Adventure Stages, Scenes, Sprites - #11945
Conversation
| String priceStr = priceStringsMap.get(priceRawVal); | ||
| if (priceStr == null) { | ||
| priceStr = String.valueOf(priceRawVal); | ||
| priceStringsMap.put(priceRawVal, priceStr); | ||
| } |
There was a problem hiding this comment.
priceStringsMap.getOrCompute?
There was a problem hiding this comment.
this is inside a drawvalue method so i'm avoiding hidden instantiating of new objects if we use method reference or lambda
Jetz72
left a comment
There was a problem hiding this comment.
I really struggle to imagine how unwrapping for-each loops, avoiding Java collections, and recycling some small objects could bring about enough of an improvement in performance or memory usage to justify the readability impact. Is this something Adventure Mode is really struggling with? And if so, are we sure there isn't some other cause?
| return locationColorID; | ||
| } | ||
|
|
||
| // updateBGM is inside act method so this is polled every frame. I wonder how to optimize this further |
There was a problem hiding this comment.
Could change it to update the BGM once every couple seconds. I think that was just there to handle walking between regions, but that doesn't necessarily need to register instantly.
| private final ArrayList<String> matchTokenList = new ArrayList<>(32); | ||
| private final StringBuilder completionBuilder = new StringBuilder(128); | ||
| private static final String[] emptyStringArray = new String[0]; |
There was a problem hiding this comment.
Is something causing the console command interpreter to fire every frame, or often enough that recycling these objects has any benefit?
There was a problem hiding this comment.
not really, but instantiating a new arraylist every method call isn't good on android.
Actually on desktop is not a problem, my concern was Android version, and yes it helps specially on mobile though as much as I wanted to keep the readability, on Android your stuck with a predetermined heap so little optimization will be best tradeoff. Imagine if you use for each loop inside draw method or act method which is called every frame, for each loop allocates iterator object vs traditional loop with zero allocation. Which will you prefer if you have limited heap? |

Reuse vars specially inside draw method the prevent excessive heap consumption, refactor vars that needs one-time init.