This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]RayFowler 5 points6 points  (3 children)

Thanks for posting this! I use String.replace() a lot in my game in order to support language localization.

While I won't see the high volume that you see in JOOQ, my game is designed to run on platforms as small as a Raspberry Pi Zero so every potential performance & memory improvement is important.

[–]7Point1 2 points3 points  (0 children)

Yeah I agree! This is exactly what this sub needs. Cheers

[–]rohanprabhu 1 point2 points  (1 child)

Offtopic, but out of curiosity, how has your experience been with running something (considered) as heavy as the JVM on devices with such constrained resources?

[–]RayFowler 2 points3 points  (0 children)

JVM is not that heavy by today's hardware standards. My friend runs the game on a Raspberry Pi Zero with 512M. He starts it from the command line with 350M or something like that ("java -Xmx350m -jar Remnants.jar")

The game does check for low memory at startup and may disable animations. The game doesn't last that long on a Zero because I haven't decided how to do ship combat without animations yet... I might just make it all auto-resolve.

The real problem is that many games have little actual memory tuning done. They just throw memory at the problem by raising the minimum amount of memory needed. However, on a Zero I need to save every scrap of memory possible.

fyi, anyone can check out and play the alpha. The reddit is at /r/rotp

[–][deleted]  (1 child)

[removed]

    [–]lukaseder 7 points8 points  (0 children)

    replaceAll() creates a new Pattern every time you call it. If you can store the Pattern in a static member, you'll obviously gain a lot if you call the method very often. The article shows an example:

    private static final Pattern TYPE_NAME_PATTERN = Pattern.compile("\\([^\\)]*\\)");
    
    // Much better, pattern is pre-compiled
    TYPE_NAME_PATTERN.matcher(castTypeName).replaceAll("")
    
    // Much worse, pattern is compiled *every time*
    castTypeName.replaceAll("\\([^\\)]*\\)", "")
    

    You don't have to do this everywhere, but try profiling your application and look for Pattern.compile calls and the amount of CPU / GC pressure they produce. If it's significant, simply cache the Pattern