3 ms·
Compression aware minifiers are definitely a thing. Instead of trying to make the code as small as possible, they will try to make it as redundant as possible.
by GuB-42 3y ago
Compression aware minifiers are definitely a thing.
Instead of trying to make the code as small as possible, they will try to make it as redundant as possible. For example by reusing names. For example "message="hello";print(message)" can be minified into "hello="hello";print(hello)", which may compress better than "a="hello";print(a)".
- jerrre 3y agoI like the idea, but just tested your specific example with https://facia.dev/tools/compress-decompress/gzip-compress/ https://facia.dev/tools/compress-decompress/gzip-compress/ and the second version compresses better, as my intuition already thought, without knowing how gzip works, because you still need a kind of identifier for repeated strings, and how much shorter than 1 byte can they be.
- tomjakubowski 3y agoOP's suggestion may work better on real life examples of source code (which would be longer and include a lot more different kinds of repeated strings)
- aidenn0 3y agoI ran some tests, and with zstd, brotli, and gzip, single-byte identifiers win on even slightly more complicated examples. If you have more than N identifiers (where N is the valid number of single-byte identifiers) then using short strings from the brotli dictionary seems to be at worst break-even for brotli. Also, there seems to be a 40-byte minimum size on zstd; Making the original example significantly smaller (or larger with repeated patterns) all yielded 40 byte files. I had to change it to e.g. print(hello);foo(hello); bar(hello) to get any difference between using "x" and "hello" as an identifier.