[Scummvm-devel] ScummVM binary size comparison

Max Horn max at quendi.de
Sat Nov 8 01:43:05 CET 2008


Am 08.11.2008 um 00:23 schrieb Neil Millstone:

> Hi Max and Team,
[...]

>
> So I used Max's handy command from an earlier post to find the biggest
> object files.  I'm compiling with my normal settings.  ARM instruction
> set mode (I'm sure thumb mode doesn't work with the current compiler),

It would still be a good thing to determine where it doesn't work,  
precisely, and to report this to upstream, to get it fixed. According  
to Robin, the binary size goes down several hundred KB, which we'll  
never be able to cut by optimizing our code manually.

> Optimisation at -Os (with a small number of files at -O2).
> $ size */*.a |sort -nr |head -n 20
>  text    data     bss     dec     hex filename
> 55703       0       0   55703    d997 ThemeEngine.o (ex gui/libgui.a)
> 40828       0       0   40828    9f7c ThemeParser.o (ex gui/libgui.a)

I actually wonder about those: I believe I understand why  
ThemeParser.o is huge (it's all the CUSTOM_XML_PARSER stuff in the  
header; and I really hope we can cut down on that quite a bit).

But I am quite confused why ThemeEngine.o is so big (on my OSX system,  
too). 50k of code -- for what? If anybody could take a look at that,  
I'd be grateful. Anyway, I have some hopes that one can reduce t

[...]

> So, any ideas on how this can be improved?

Add
#define DISABLE_FANCY_THEMES
#define VECTOR_RENDERER_FORMAT 1555
resp. the equivalent -D options. Then recompile. That might help a  
little bit.


Next, I noticed that the built-in theme takes up 35k alone (I think  
the old one used a similar number, though). Specifically, gui/themes/ 
default.inc is 38870 (of course, you have to subtract a couple  
thousand bytes for quotation marks etc.).

With a trivial trick I was able to save 4k in my binary: I opened gui/ 
themes/default.inc, and replaced all occurrences of " = " by "=", and  
likewise ", " by "," -- after removing several thousand spaces this  
way, default.inc was down to 35888 bytes, and the binary size was  
reduced by 4096 bytes for me.

Since the DS only needs the 320x240 GUI layout, I stripped the high- 
res layout (by removing "gui/themes/scummclassic/classic_layout.stx",  
then running "python scummtheme.py default scummclassic". Then removed  
the whitespaces. Result: default.inc at 20976 bytes. In my case, the  
binary now was 16384 bytes smaller (on OS X, it'll always be a  
multiple of 1024 for technical reasons.).

Extending this idea, we could shrink the theme even more if we apply  
some kind of compression. Using a perl script / preprocessor magic, we  
could automatically replace lots of keywords on systems with low  
memory (both in the XML file as well as in the theming code itself):  
"foreground" -> "fore", "drawdata" -> "dd", "drawstep" -> "ds", etc..  
In addition, we could store the data zlib compressed and decompress it  
on the fly.

No matter what we do, XML by itself always is wasteful, and doesn't  
compress *that* well... We could avoid this, if we developed a way to  
just dump the whole theme into a binary file, without concern for  
forward compatibility, and compiled that in. Then we could also omit  
the XML parser, and save even more space. But I am not sure whether  
that would be worth it...

BTW, is you code including scummclassic.zip or scummmodern.zip? You  
shouldn't need either, the built-in theme should suffice.


Oh, and do we really need super-expressive internal names for widgets  
and dialogs? "GameOptions_Volume.EnableTabCheckbox" and similar  
strings really add up to a lot.


Anyway, there is still a lot more stuff that grew, and we need to look  
into this.

Bye,
Max





More information about the Scummvm-devel mailing list