Thus spake Joel Uckelman:
I’ve been thinking about this again, in light of the contentous debate
happening on ConsimWorld about heap sizing.
It’s easy to check how much memory would be used if all of the images in a
module in it were loaded at once. It took me about 10 minutes to write a
program which does this. So, I can find out that, e.g., the images in the
Clash of Monarchs module amount to 152MB in memory, and that Combat
Commander: Europe with all of the extensions loaded weighs in at 1896MB.
For CoM, that number might be pretty close to the minimum memory you need
to use the module, but the number for CC:E is nonsense—it includes every
map, and every card in every deck, despite that you only play with one map
and two decks at a time.
This problem is even worse for games where the same maps are not setup for
each scenario, or where the user picks which ones he wants via the board
chooser. For CC:E, our knowledge of the game tells us that we never need
to load more than one map at a time; for these cases, I have no idea what
we could do to analyze the module automatically to determine a minimum
feasible max heap size.
I wonder if we could instead do something adaptive. Two things we can
track esaily are OutOfMemoryExceptions and cache misses. It’s clear that
the heap is too small for what’s being put into it when an OOME happens,
so in that case we could automatically turn on memory-mapped images or
increase the max heap size somewhat. (Maybe increase by 10% on each OOME,
so that we’ll find something which works without overshooting too much?)
Frequent cache misses are the other symptom of having a heap which is too
small. Some image cache misses are necessary—every image requested will
be a miss the first time—and most machines will have sufficient spare
CPU cycles that occasional cache misses won’t be noticeable for the user.
If cache misses become frequent, however, the cache might start to thrash.
E.g., I’ve found that it’s possible to get the Case Blue module to get
into a load-clear-load cycle if you give it just enough heap to load one
or two maps, but not enough to load more, and then you scroll to a place
where several maps come together. Cache misses are something we can
measure. It wouldn’t be hard to modify the image cache to track how many
non-initial misses are happening per second. The only trick here is
figuring out if there’s a number of misses per second which indicates
insufficient heap space and whether that number is (more or less) constant
across machines. (My gut feeling is that it should be.)
Post generated using Mail2Forum (mail2forum.com)