Entropy of AS3 source code

241 Views Asked by At

I'm trying to decide if I should generate AS3 code for a certain complicated configurable set of business-logic rules, or should I express them as data, and write a state machine in AS3 to interpret it.

My goal is to get smallest compiled swf size. Speed is not an issue. Implementation complexity is not an issue as well. (Both within rational limits, of course.)

I can not disclose sufficient details, and I understand that I probably should do experiment instead of asking, but my question is:

What is average compression ratio for AS3 source when compiled to swf? How much bytes of swf per kilobyte of source code?

(I perfectly understand that the answer would be a very rough figure at best.)

2

There are 2 best solutions below

1
martineno On

Remember that SWF files are already zlib compressed so that for the most part might erase any relative gains by going either data way or code way.

If the initial load speed is what you are going after you can always factor out chunks of your code and load it on demand from another SWF file.

2
alxx On

Some facts about the compiled SWF:

  • class names are preserved
  • member names are preserved
  • local variable names are not preserved
  • comments and whitespace are stripped

So, the ratio would depend on length of identifiers, comments and even tabs-or-spaces preferences. If you run your result SWF through obfuscator which replaces class names with something like A0, A1, etc. you should save some bytes.

Your state machine idea seems to be the most promising - code is written once, and rules can be written in compact way. If you can pack small numbers into one int, it will be better (there are no integers in AS3 less than 4-byte ints and uints).