farnulfo / ai-contest

Automatically exported from code.google.com/p/ai-contest
0 stars 0 forks source link

The java code is unreasonably slow at various string-handling and logging operations #78

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run a long game with lots of fleets
2. Visualize it with ShowGame.jar
3. Wait five minutes while your computer uses 100% CPU and swaps before 
bringing up the interface

I think the string parsing code is doing something really bad, but I don't know 
what off-hand.

Original issue reported on code.google.com by andy.sloane on 9 Sep 2010 at 8:40

GoogleCodeExporter commented 9 years ago
HAHAHAHAHAHA!

    String playbackString = "";
    int ch;
    try {
      while ((ch = System.in.read()) >= 0) {
        playbackString += (char)ch;
      }

That would explain it.  Creating branch issue78 with patch.

Original comment by andy.sloane on 9 Sep 2010 at 6:02

GoogleCodeExporter commented 9 years ago
I identified a few more points in the code where it could be sped up a lot by 
doing smarter handling of strings, and I'm going to commit those to the branch 
as well.

The game engine (PlayGame.jar) actually spends most of its time opening, 
flushing, and closing log files, so I optimized that as well (the Game class 
holds a buffered file object which is loaded on demand now and closed when the 
object is destroyed).  If there are multiple game engines expecting to 
interleave messages in a single log, that will no longer work, but the 
resulting code is almost twice as fast.

Original comment by andy.sloane on 9 Sep 2010 at 9:30

GoogleCodeExporter commented 9 years ago
Fixed in latest starter packs.

Original comment by andy.sloane on 10 Sep 2010 at 6:42