GameState wastes a lot of memory

I was looking at a heap dump in a profiler (jvisualvm, which is pretty good
and ships with Sun’s JDK) last night when I noticed that the next largest
consumer of memory for us, after int[]—all of our BufferedImages contain
arrays of integers as data—is char[], most of which are held by Strings.
One String in particular is a major outlier: GameState.lastSave. When I
opened the campaign setup for The Longest Day, GameState.lastSave was more
than 2 million characters long. So far as I can see, all that
GameState.lastSave is used for is to check whether the game state has been
modified since the last save, so we could replace this 2MB String with a
boolean.

2009/3/27 uckelman <messages@forums.vassalengine.org (messages@forums.vassalengine.org)>

Well, I’m not using it for anything…

It’s relatively easy to check where it is accessed to, so go ahead.

  • M.

Post generated using Mail2Forum (mail2forum.com)

Isn’t this being used to compare the current gamestate with the last game state saved? I don’t see how a boolean would help. I go to save the current game, I generate a gamestate, I need the old gamestate to compare it to, not a boolean. This code is only used in the Editor, so top performance is a low priority.

B.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

On Mar 27, 2009, at 4:03 PM, Brent Easton wrote:

Well, I suppose that if the memory was truly critical (and 2MB is only
about the size of a moderate-sized map), one could go to just storing
something like an MD5 hash of the state. But it hardly seems that
this is likely to be a major space issue unless it gets to be at least
10 or more times this size.

-Tom.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Thus spake “Brent Easton”:

GameState.lastSave is set in GameState.setup(), so it’s used any time
a saved game is loaded.

Since the only thing lastSave is used for is the comparision in isModified(),
all we’d need to do is set boolean flag to true whenever a modification
occurs, and back to false after a save.


J.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

That’s the way most programs do it! Go for it.

  • M.

Post generated using Mail2Forum (mail2forum.com)