Skip to content

Refactor Adventure Stages, Scenes, Sprites - #11945

Merged
kevlahnota merged 14 commits into
masterfrom
optimizeadvstages
Sep 21, 2026
Merged

kevlahnota merged 14 commits into
masterfrom
optimizeadvstages

Conversation

@kevlahnota

@kevlahnota kevlahnota commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

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

@kevlahnota kevlahnota added the Adventure For the Adventure Module label Sep 18, 2026
@kevlahnota kevlahnota changed the title Refactor Adventure Stages Refactor Adventure Stages, Scenes Sep 18, 2026
Comment on lines +1049 to +1053
String priceStr = priceStringsMap.get(priceRawVal);
if (priceStr == null) {
priceStr = String.valueOf(priceRawVal);
priceStringsMap.put(priceRawVal, priceStr);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

priceStringsMap.getOrCompute?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is inside a drawvalue method so i'm avoiding hidden instantiating of new objects if we use method reference or lambda

@Jetz72 Jetz72 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well I think the soundsystem needs update but i'm not looking at it right now but take a look:
image
the jfr was recorded 1 minute only IIRC

Comment on lines +44 to +46
private final ArrayList<String> matchTokenList = new ArrayList<>(32);
private final StringBuilder completionBuilder = new StringBuilder(128);
private static final String[] emptyStringArray = new String[0];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is something causing the console command interpreter to fire every frame, or often enough that recycling these objects has any benefit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really, but instantiating a new arraylist every method call isn't good on android.

@kevlahnota

kevlahnota commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor Author

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?

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?

@kevlahnota kevlahnota changed the title Refactor Adventure Stages, Scenes Refactor Adventure Stages, Scenes, Sprites Sep 20, 2026
@kevlahnota
kevlahnota marked this pull request as ready for review September 20, 2026 15:17
@kevlahnota
kevlahnota merged commit 09ec07a into master Sep 21, 2026
10 checks passed
Comment thread forge-gui-mobile/src/forge/adventure/stage/MapStage.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Adventure For the Adventure Module Mobile Performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants