Improving performance for large games

In the course of working on Hadean Lands, I’ve done some profiling work. This game is supposed to wind up on mobile devices, after all. (iOS CPUs have sped up orders of magnitude since I started this project, but still…)

I7’s library (and the Standard Rules) have a few trouble spots – places where the library iterates through the entire object list, or the list of the “thing” class. Most of these occur in the “look” action. This is not a big deal in a medium-sized game, but my game contains 800 objects (420 things), so it turns into a noticeable slowdown.

I’ve extracted my performance improvements and posted them as an extension:

eblong.com/zarf/glulx/Large%20Game%20Speedup.i7x

This will only work with the current Inform build, 6G60. Yes, there’s a big I7 update due in a week and a half, and I’ll have to update my extension for that. I’ll keep links to both versions up, actually, because some authors may not want to spend the effort to transition a large game over to the new Inform.

If you want to replicate my profiling work, you can recompile Glulxe with the VM_PROFILING option.

A simpler alternative, which doesn’t do full profiling but just gives a total of CPU cycles and milliseconds per command: check out the “debugging” branches of Glulxe and CheapGlk. (github.com/erkyrath/cheapglk/tree/debugger) Build Glulxe with the VM_DEBUGGER option and then run with the options:

glulxe -D --cpu output.ulx

Wow! This looks cool! An initial full-test walkthrough of A Roiling Original sped up 10%, and that’s before using the “empty” adjective and so forth. (Though I haven’t run anything replicable.)

The looking and locale priority seem to be a heck of a lot quicker. I expect I’d get >>10% if the game didn’t go to town on indexed text for its core mechanic.

Probably it was made on purpose to speed up the games, but some things are omited. For exemple with this code:

kitchen is a room.

The wooden table is a supporter in kitchen.
The apple is on the wooden table. 

will display:

While with the extension it will only display:

I tried this because in my (French) game, I got some strange behaviors, for example I got this:

(on the bed he could see a table!)

while without the extension I expects this:

But maybe it’s because of some conflits with the French extension. Many things will probably change with the new I7 release so it’s not a big deal.

Nothing is omitted on purpose, except as documented. I’ll try to see what I did wrong.

Yeah, my WriteListFrom changes were incorrect. I’ve uploaded version 2, which is not as fast but should behave correctly. I’ll think about better ways to improve that.

Please let me know if you find other bugs.

I haven’t found other bugs, but I’ve hit a big game pretty hard with test scripts and found no differences with version 2 vs. my game without either versions. So that seems good.

I’ve uploaded release 3 of this extension (same URL). This regains most of the speed of the first version, hopefully without the bugs.

aschultz, if you try it with your test scripts, please post and say how it goes. :slight_smile:

Out of curiosity, in the example given for the extension, why do you declare “There are 50 clones.” eight times instead of, say, “There are 100 clones.” 4 times?

Inform has some maximum. “400” doesn’t work. I started with 40 lines of “10 clones” and increased it a few times until it wasn’t too much code.

Yeah, 100 is the maximum.

I added a small change which knocks another big chunk off the execution time. (Highly optimized replacements for lines like “now all things are not mentioned”.)

eblong.com/zarf/glulx/Large%20Game%20Speedup.i7x

This looks very cool. You mentioned you were planning to make a version for the new build. Please let us know if you have! I’d love to try it out as my game has a few thousand objects now and it is definitely slow on “look”.

I think I am going to wait for the bug-fix I7 release. At least one of the mechanisms I’m hacking (the grouping-together activity) will be changed under the covers.