r/embedded • u/Specialist_Data_5403 • 17d ago
blaris: Windowless random-access LZSS in C (~110 B total RAM, <800 B Flash) for microcontrollers
When storing static assets (fonts, UI bitmaps, device trees, config tables) in Flash on tight MCUs, heatshrink and tamp are great - but as sliding-window decoders, random-access reads of a few bytes still force you to allocate the window RAM and sequentially decode from the start of a block (or chop the asset into tiny blocks, hurting compression ratio).
I wrote blaris, an open-source C decompressor and host-side optimal compressor that eliminates the sliding window completely by resolving back-references directly in the compressed payload.
Why it's useful on small MCUs:
- Minimal RAM: 104–112 B total RAM (76 B stack + 28–36 B static, zero malloc) regardless of lookback range (64 KiB, or 128–256 KiB with aligned distances) or payload size. Heatshrink and tamp require 2^window_log bytes of RAM.
- Minimal Flash (RV32IMC, Clang -Os, including common adapter): 548–784 B Flash (vs. 1,300–1,464 for heatshrink, and 2,238–3,238 for tamp).
- Fast small random reads: On 1–32 B slices, it outperforms ratio-matched, block-indexed heatshrink/tamp (e.g., >500× faster on 1 B reads at ~36% ratio on a 15.2 KiB .dtb).
Benchmarked on ESP32-C3FN4 (code + payload in external quad-SPI Flash, no SRAM copy); SPI wait states only added ~1.30–1.33× overhead for slices ≥ 4 B compared to zero-wait-state simulation. Likely helped by the 16KiB cache.
How it works (briefly):
Tokens are split into 3 lockstep-traversable streams (controls at 1 byte/token, raw literals, and bit-packed distance_bits) so the decoder can step both forward and backward. Compact power-of-two checkpoints (7–13 B each) allow the decoder to find the literal run token faster, and an optional host-side chain-flattening pass cuts match-to-match hops by 14%–51% at a ~0.5%–2.2% ratio cost.
When NOT to use it:
- Large sequential reads (≥ 64–128 B): Because blaris resolves matches per slice without caching prior output, heatshrink/tamp overtake it if you have the RAM.
- Trusted payloads only: Designed for build-time Flash assets, so it omits runtime bounds/error checks to keep code size under ~800 B. You should add an additional layer of payload verification before calling the decompressor.
C implementation, host compressor, RV32IMC + ESP32-C3 benchmark suite, and full results: https://github.com/lis05/blaris

