Shrinky-Dink Python
permalink categories: programming originally posted: 2006-01-11 22:25:08About eighteen months ago, I realized that my plan for level creation for my game was just not going to be feasible. I'd planned to write all levels as FORTH scripts, and... well, not only is that a totally un-visual way of designing fun levels, but I was constantly tripping over the programming differences between FORTH and C (between FORTH and every other language under the sun, really). I'd wanted to use Python for scripting in my game, but the runtime was just too big. The Python 2.4.2 DLL weighs in at 1.86MB, and zips down to 877k. Given that my target was about 5MB for the full game, I just couldn't afford the space. So I hacked together something that I knew I would end up detesting—a prediction that has come oh-so-true—whose only saving graces are that it works and it's about 20x smaller.
After I'd finished the initial development, my friend Marc Kwiatkowski mentioned to me that you can make a much smaller Python DLL by recompiling it yourself. I remember him (or someone) claiming you could get it down to 160K; I'll believe that when I see it. But on this past Monday I experimented with it. On my final try, the DLL was 570k, and it zipped to 260k. It smoke-tests and seems to work fine. What did I remove? Unicode support, doc strings, and every module implemented in C. My Python DLL still has all the built-in types and functions, and all the language keywords, but scarce little else.
If I'd known that, I would have definitely gone with Python. Ah well, hopefully there'll be a next time.
When I posted about this to another venue, someone asked if I'd looked into Stackless Python. I hadn't, but the short story is: Stackless is usually a little bit bigger than the normal Python DLL. Also, they're still only at version 2.3, which isn't a major crime, but why go with that when I could have 2.4. Stackless is battle-tested technology, getting heavy-duty use for the outer-space MMORPG Eve Online. But my threading needs are slight, and even just conventional Python would be fantastic for my games.