ENGINEERING · ON-DEVICE COMPRESSION

How do you fit three times the message through a radio that only holds 239 bytes?

A LoRa radio has room for only a few sentences before its packet fills up. I built a tiny, exact compressor for mesh messages, learned where the real gains were, and stopped when the remaining problem became bigger than the product I was trying to ship.

PACKET BUDGET · INTERACTIVE MODEL
MESSAGE

Meet at the north trailhead at 18:30. Bring water.

Checks the selected UTF-8 byte sequence and its CRC-16 envelope.
Recorded codec validation
3,506 / 3,506 exact round trips
Worst-case policy
Raw fallback if compressed ≥ raw
Claim boundary
Offline sizing, not field delivery
Figure 1. Interactive packet-budget model. It counts the actual UTF-8 bytes in each sample, then estimates a compressed packet using the measured 80 KB mixer ratio and a 3-byte model-ID + CRC envelope. This is a sizing model, not a browser implementation of the research codec.
2.41×
payload-only compression on held-out SMS
3,506 / 3,506
exact round trips, including binary and multilingual inputs
239 B
maximum Meshtastic payload
2.895
bits per byte from the 313K-parameter GRU pilot

The postcard with a 239-byte limit

A LoRa mesh is like a chain of people passing postcards across a field. Every relay has to repeat every card, so a long message costs time not once but at every hop. On Meshtastic, the payload budget is at most 239 bytes. That is enough for a short update, but it gets tight quickly when a team is trying to send a location, a status report or an ordinary sentence over a crowded channel.

The question was deliberately small: could a model that fits on an ESP32 help text take less room, without ever changing the message? The decoder had to reproduce every byte exactly on iOS, Android and embedded hardware. A compressor that occasionally turns a coordinate into a different coordinate is not compression; it is a new kind of emergency.

Compression is prediction with a receipt

The basic idea is simpler than the word model makes it sound. If I tell you that a message begins with 'meet me at the', you can make a good guess about what comes next. A compressor writes down common, predictable continuations with fewer bits and makes rare surprises cost more. Arithmetic coding is the receipt: it turns the probabilities into a reversible stream of bits.

I started with an integer context mixer. It looks at a handful of recent bytes through several small context tables, combines their guesses with fixed-point arithmetic, and feeds that probability to an arithmetic coder. Everything is bounded and deterministic. The same bytes in must produce the same bits out, regardless of whether the decoder is a phone or a microcontroller.

The first benchmark was promising

On 1,000 held-out SMS messages, the full integer mixer reduced payload size by 2.41×, or 3.33 bits per byte. A plain order-2 n-gram plus arithmetic coding reached 2.21×. The difference matters, but it is also the first warning in this story: most of the gain was coming from classical context modeling, not from a mysterious learned architecture.

The smaller 80 KB-table version still reached 2.08×. Against the same test set, Unishox2 reached 1.54×, a zstd dictionary 1.49×, smaz2 1.44× and Brotli 1.19×. Those are payload-only numbers. Packet headers, a codec identifier and integrity checks reduce the end-to-end gain, so this was evidence for a codec, not evidence that a live mesh would suddenly carry 2.41 times as much traffic.

Held-out SMS payload compression ratio (larger is better)

Integer mixer · 640 KB tables
2.41×
Order-2 n-gram + arithmetic coding
2.21×
Integer mixer · 80 KB tables
2.08×
Unishox2
1.54×
zstd + 16 KB dictionary
1.49×
smaz2
1.44×
Brotli
1.19×
Figure 2. The measured payload-only ratios from the held-out SMS benchmark. Larger is smaller-on-the-wire. The 640 KB mixer is not an MCU deployment claim; the 80 KB row is the constrained comparison.

Lossless means surviving the weird messages

A demo that only compresses ordinary English is a magician choosing the card. Mesh users can send emoji, accented text, corrupted-looking bytes and messages containing words the model has never seen. I rebuilt the codec at the byte level with an explicit end-of-message bit and a raw fallback for expansion cases.

That produced 3,506 exact round trips: 12 synthetic held-out messages, 3,000 random multilingual or emoji strings, 500 random binary strings and the SMS benchmark inputs. Some inputs got larger—random binary could expand by as much as 2.29×—which is why the raw fallback is part of the design. A checksum or authenticated tag detects corruption; it must reject a damaged stream rather than display a plausible but wrong message.

Bit-exactness is the unglamorous part that makes the rest real. A floating-point predictor can make a slightly different rounding choice on two devices, which gives the range coder a different next bit; from there the decoder is lost in the woods. This version kept the probabilities and mixer in integer arithmetic, recorded the model version, and checked CRC-16 over the version plus the original message before display. The little test above exposes the same boundaries: UTF-8 bytes, packet envelope and an integrity check—not a hand-wavy promise that two devices will probably agree.

The neural model did not clear the gate

The obvious next bet was a tiny learned byte model. A 313K-parameter GRU pilot reached 2.895 bits per byte, better than the large-table mixer, and weight-only int8 quantization barely changed the smaller pilot. That was encouraging, but it did not answer the engineering question yet.

The gate I wrote down was tougher: beat the 256 KB integer-mixer baseline by at least 15% while staying within 256 KB. The 313K GRU needed roughly 306 KB in int8 form, and its result was not enough to clear that target. It still needed a C99 port, device latency measurements and bit-exact cross-language tests. A float pilot on a small text set is not an embedded product.

The channel was not mostly text

Then the premise moved. A public Meshtastic capture showed that text was only about 0.7% of packets and airtime; node information, position and telemetry dominated. Even a perfect text compressor would leave most of a congested channel untouched. The more useful research direction became state-conditional coding: compress recurring position, telemetry and node fields against what a receiver already knows, with periodic keyframes and a safe fallback.

That is a much better systems problem, but it is also a different project. It needs trace replay, firmware integration, compatibility policy and real-device field trials. Treating a good text-codec prototype as proof of that whole program would have made the claim larger than the evidence.

What would have come next

The next milestone was not another prettier compression chart. It was a C99 core with the same bounded integer operations, plus Swift, Kotlin/JNI and ESP32 bindings. A cross-language harness would feed every implementation the same corpus and require byte-for-byte identical encoded streams and decoded outputs. Then come the unromantic tests: fuzzed packets, model-version mismatch, a flipped bit in the range-coded payload, a full composer limit, and the raw fallback whenever the envelope is not smaller than the original.

The learned-model route had its own gate. A ≤256 KB int8 model would have needed to beat the 256 KB classical mixer by at least 15%, then earn a place on hardware by reporting encode/decode latency, RAM, energy and binary size—not just bits per byte in a notebook. The meaningful result would have been a Pareto frontier: a clear picture of what each byte of model memory buys, and where it stops buying enough.

The ambitious path was whole-mesh coding. A receiver could use the last known NodeDB state to send a short delta for a position or telemetry update, with periodic full keyframes so dropped packets cannot poison later decoding. That needs a trace replay before a field trial, compatibility modes for mixed fleets, and delivery measurements on a deliberately congested mesh. The original target was at least a 10-point first-try delivery improvement for 100–200-byte messages and a ≥30% airtime cut from state-conditional broadcasts. Those were planned gates, not results.

Why it is archived

Mesh Messaging Codec is shelved, not because the first numbers were bad, but because they made the next decision clearer. The work established a lossless byte-level baseline, showed where a tiny learned model might help, and exposed that text alone is not the mesh bottleneck. The remaining work belongs with a larger on-device-model and whole-mesh research program, not as a half-finished app marketed as a breakthrough.

That makes this a useful write-up to keep: it records the measurements, the safety constraints and the point where the original question stopped being the right one. The explainer and research plan are preserved; no field-delivery, adoption or device-speed result is claimed here.

← All writingDiscuss this →
RELATED WRITING
ENGINEERINGOctober 2026

The trace was flat because every chain node had disappeared

You cannot test a debugger on code that works. I built an agent designed to fail, pointed my own time-travel debugger at it, and found that the debugger was the thing with the bugs.

Read →
ENGINEERINGOctober 2026

A fixed budget for answering: which chunk caused this?

When a RAG system says something false, you want to know which retrieved passage it came from, if any. VectorLens answers that on your own machine, with two lines of code and a fixed budget per answer. It is built like an emergency room: a quick check for everyone, a closer look only for the cases that need it.

Read →