Minification (Pico-8)
Shrinko8 - an aggressive cart minifier (+ linter & other tools) - online / lexaloffle
Sometimes your cartridge fits in the token count, but not the characters count / compressed size, so you can’t export it until you reduce the number of characters in the cartridge. - Aggressive Lua code minification and debug code stripping
-
r/pico8 - A set of Pico-8 cart tools, with a focus on shrinking code size.
- Tokens: 8192
- Characters: 65’536
- Compressed Code Size: 15’616
Compression limit
Because there is a small, fixed amount of space available to encode the cart in the image, PICO-8 uses compression to reduce the size of the cart’s source code. The compressed code size must be under a certain limit for the save to succeed. As of 0.2.2c, this limit is 15,616 bytes.
PXA File Format
pico8 stores its cartridges in a custom compressed format called PXA. basically, it stores data in chunks. each chunk is a specific type, CHR, REF, or RAW
coming up with new ways to make my code horrific but slightly smaller when compressed:
- changing all my loops (e.g.
for j=1,8 do) to use the same index variable (j) and start number, so that the loop header compressed neatly into a larger REF chunk. - don’t store variables if you can help it. writing
x=stat(32)to get the mouse’s xpos and then using it ~6 times was 1 byte longer than just callingstat(32)6 times. surprising!
see also PXAVizualiser
Compressor
-
PX9 / PX8 - PX9 is a lightweight gfx & map compression library, intended to replace PX8. It uses the same ideas and interface as px8, but is smaller (~297~x 214 tokens to decompress), and requires zero configuration.
- New Byte Compressor 2022
- Adventures in data compression (2021) - compare different technics and algorithm in pico-8 context:
- My Compressor (2018)
- SRAM Smasher! (2018)
- Binary Image Compressor (2016)
see also
- Motivation Crisis: Compression Limit?
- A compressed size limit rant
- Alex Kidd Pico Part 3: Code & Music limitations
Token Optimisation
MultiCart
- From one Pico-8 cart to many
- Picocraft: Pico8 Sprite and maps Tricks - Graphics Workflow with PX9
- show multicart and upper memory usage
- Picocraft: Pico8 Sprite and maps Tricks - Graphics Workflow with PX9
Sprite Optimisation
- rectpack2D / HN - A header-only 2D rectangle packing library written in modern C++.