micropython / micropython

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
https://micropython.org
Other
18.76k stars 7.5k forks source link

Minifier for frozen modules - write own or use existing #1309

Closed pfalcon closed 8 years ago

pfalcon commented 9 years ago

Before writing my own minifier I went to study prior art and e.g. found https://github.com/liftoff/pyminifier , which doesn't just compresses indents (trivial), removes whitespace (supposedly easy), but also renames identifiers (I'd probably skip writing that). W/o the latter step it gives figure of 1358 -> 640 bytes compression (also kind of info I was looking for).

dpgeorge commented 9 years ago

I always err on the side of do it yourself/myself, but renaming identifiers is pretty nifty and non-trivial, so might be sensible to use that pyminifier.

Other option would be to compress frozen modules and decompress on the fly when lexing (pretty easy to do). Then minification is not needed.

pfalcon commented 9 years ago

Other option would be to compress frozen modules and decompress on the fly when lexing (pretty easy to do).

Really? Depends on compression method I'd say. uzlib still doesn't have stream operation mode, even though it's "easy".

dpgeorge commented 9 years ago

uzlib still doesn't have stream operation mode,

Oh, right, well then it's not that easy. Interfacing to the lexer with an arbitrary stream is the easy bit.

pfalcon commented 8 years ago

As an update, I experimented with writing own minifier, and actually kinda have it, but now the biggest issue is to test that it produces correct code. And given #1527, maybe it's no longer that important.

pfalcon commented 8 years ago

Closing this as no longer relevant per above comment.