micropython/py
Jim Mussared 154b4eb354 py: Implement "common word" compression scheme for error messages.
The idea here is that there's a moderate amount of ROM used up by exception
text.  Obviously we try to keep the messages short, and the code can enable
terse errors, but it still adds up.  Listed below is the total string data
size for various ports:

    bare-arm 2860
    minimal 2876
    stm32 8926  (PYBV11)
    cc3200 3751
    esp32 5721

This commit implements compression of these strings.  It takes advantage of
the fact that these strings are all 7-bit ascii and extracts the top 128
frequently used words from the messages and stores them packed (dropping
their null-terminator), then uses (0x80 | index) inside strings to refer to
these common words.  Spaces are automatically added around words, saving
more bytes.  This happens transparently in the build process, mirroring the
steps that are used to generate the QSTR data.  The MP_COMPRESSED_ROM_TEXT
macro wraps any literal string that should compressed, and it's
automatically decompressed in mp_decompress_rom_string.

There are many schemes that could be used for the compression, and some are
included in py/makecompresseddata.py for reference (space, Huffman, ngram,
common word).  Results showed that the common-word compression gets better
results.  This is before counting the increased cost of the Huffman
decoder.  This might be slightly counter-intuitive, but this data is
extremely repetitive at a word-level, and the byte-level entropy coder
can't quite exploit that as efficiently.  Ideally one would combine both
approaches, but for now the common-word approach is the one that is used.

For additional comparison, the size of the raw data compressed with gzip
and zlib is calculated, as a sort of proxy for a lower entropy bound.  With
this scheme we come within 15% on stm32, and 30% on bare-arm (i.e. we use
x% more bytes than the data compressed with gzip -- not counting the code
overhead of a decoder, and how this would be hypothetically implemented).

The feature is disabled by default and can be enabled by setting
MICROPY_ROM_TEXT_COMPRESSION at the Makefile-level.
2020-04-05 14:20:57 +10:00
..
argcheck.c py: Use preprocessor to detect error reporting level (terse/detailed). 2020-04-05 14:11:51 +10:00
asmarm.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
asmarm.h
asmbase.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
asmbase.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
asmthumb.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
asmthumb.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
asmx64.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
asmx64.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
asmx86.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
asmx86.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
asmxtensa.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
asmxtensa.h
bc.c py: Use preprocessor to detect error reporting level (terse/detailed). 2020-04-05 14:11:51 +10:00
bc.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
bc0.h
binary.c all: Fix implicit casts of float/double, and signed comparison. 2020-03-30 12:04:21 +11:00
binary.h
builtin.h extmod/uasyncio: Add optional implementation of core uasyncio in C. 2020-03-26 01:25:45 +11:00
builtinevex.c py/builtinevex: Support passing in a bytearray/buffer to eval/exec. 2020-02-28 12:45:36 +11:00
builtinhelp.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
builtinimport.c py: Use preprocessor to detect error reporting level (terse/detailed). 2020-04-05 14:11:51 +10:00
compile.c py: Use preprocessor to detect error reporting level (terse/detailed). 2020-04-05 14:11:51 +10:00
compile.h
dynruntime.h py/dynruntime.mk: Set MICROPY_ENABLE_DYNRUNTIME instead of per module. 2020-04-05 14:13:02 +10:00
dynruntime.mk py/dynruntime.mk: Set MICROPY_ENABLE_DYNRUNTIME instead of per module. 2020-04-05 14:13:02 +10:00
emit.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
emitbc.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
emitcommon.c
emitglue.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
emitglue.h
emitinlinethumb.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
emitinlinextensa.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
emitnarm.c
emitnative.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
emitnthumb.c
emitnx64.c
emitnx86.c
emitnxtensa.c
emitnxtensawin.c
formatfloat.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
formatfloat.h
frozenmod.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
frozenmod.h
gc.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
gc.h
grammar.h
lexer.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
lexer.h
makecompresseddata.py py: Implement "common word" compression scheme for error messages. 2020-04-05 14:20:57 +10:00
makemoduledefs.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
makeqstrdata.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
makeqstrdefs.py py: Implement "common word" compression scheme for error messages. 2020-04-05 14:20:57 +10:00
makeversionhdr.py all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
malloc.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
map.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
misc.h py: Implement "common word" compression scheme for error messages. 2020-04-05 14:20:57 +10:00
mkenv.mk
mkrules.mk py: Implement "common word" compression scheme for error messages. 2020-04-05 14:20:57 +10:00
modarray.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
modbuiltins.c py: Use preprocessor to detect error reporting level (terse/detailed). 2020-04-05 14:11:51 +10:00
modcmath.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
modcollections.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
modgc.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
modio.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
modmath.c all: Convert exceptions to use mp_raise_XXX helpers in remaining places. 2020-03-18 17:26:19 +11:00
modmicropython.c py/modmicropython: Add heap_locked function to test state of heap. 2020-03-11 16:54:16 +11:00
modstruct.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
modsys.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
modthread.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
moduerrno.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
mpconfig.h extmod/uasyncio: Add optional implementation of core uasyncio in C. 2020-03-26 01:25:45 +11:00
mperrno.h
mphal.h
mpprint.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
mpprint.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
mpstate.c
mpstate.h
mpthread.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
mpz.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
mpz.h tools/codeformat.py: Eliminate need for sizeof fixup. 2020-03-11 14:34:40 +11:00
nativeglue.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
nativeglue.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
nlr.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
nlr.h
nlrpowerpc.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
nlrsetjmp.c
nlrthumb.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
nlrx64.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
nlrx86.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
nlrxtensa.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
obj.c py: Use preprocessor to detect error reporting level (terse/detailed). 2020-04-05 14:11:51 +10:00
obj.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objarray.c all: Fix implicit casts of float/double, and signed comparison. 2020-03-30 12:04:21 +11:00
objarray.h
objattrtuple.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objbool.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objboundmeth.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objcell.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objclosure.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objcomplex.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objdeque.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objdict.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objenumerate.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objexcept.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objexcept.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objfilter.c
objfloat.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objfun.c tools/codeformat.py: Eliminate need for sizeof fixup. 2020-03-11 14:34:40 +11:00
objfun.h
objgenerator.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objgenerator.h
objgetitemiter.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objint.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objint.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objint_longlong.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objint_mpz.c all: Remove spaces inside and around parenthesis. 2020-03-28 23:36:44 +11:00
objlist.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objlist.h
objmap.c
objmodule.c extmod/uasyncio: Add optional implementation of core uasyncio in C. 2020-03-26 01:25:45 +11:00
objmodule.h
objnamedtuple.c py: Use preprocessor to detect error reporting level (terse/detailed). 2020-04-05 14:11:51 +10:00
objnamedtuple.h
objnone.c
objobject.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objpolyiter.c
objproperty.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objrange.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objreversed.c
objset.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objsingleton.c
objslice.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objstr.c py: Use preprocessor to detect error reporting level (terse/detailed). 2020-04-05 14:11:51 +10:00
objstr.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objstringio.c py/objstringio: Expose tell() on StringIO and BytesIO objects. 2020-03-11 14:43:03 +11:00
objstringio.h
objstrunicode.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objtuple.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objtuple.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objtype.c py: Use preprocessor to detect error reporting level (terse/detailed). 2020-04-05 14:11:51 +10:00
objtype.h
objzip.c
opmethods.c
pairheap.c py/pairheap: Properly unlink node on pop and delete. 2020-03-26 01:21:04 +11:00
pairheap.h py/pairheap: Add helper function to initialise a new node. 2020-03-26 01:21:04 +11:00
parse.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
parse.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
parsenum.c py: Use preprocessor to detect error reporting level (terse/detailed). 2020-04-05 14:11:51 +10:00
parsenum.h
parsenumbase.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
parsenumbase.h
persistentcode.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
persistentcode.h
profile.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
profile.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
py.mk py: Implement "common word" compression scheme for error messages. 2020-04-05 14:20:57 +10:00
pystack.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
pystack.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
qstr.c py: Implement "common word" compression scheme for error messages. 2020-04-05 14:20:57 +10:00
qstr.h py: Implement "common word" compression scheme for error messages. 2020-04-05 14:20:57 +10:00
qstrdefs.h
reader.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
reader.h
repl.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
repl.h
ringbuf.c
ringbuf.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
runtime.c py: Use preprocessor to detect error reporting level (terse/detailed). 2020-04-05 14:11:51 +10:00
runtime.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
runtime0.h
runtime_utils.c
scheduler.c
scope.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
scope.h
sequence.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
showbc.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
smallint.c
smallint.h
stackctrl.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
stackctrl.h
stream.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
stream.h py/stream.h: Include sys/types.h to get size_t and off_t for POSIX API. 2020-03-25 01:00:52 +11:00
unicode.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
unicode.h
vm.c
vmentrytable.h
vstr.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
warning.c