ALEC β Adaptive Lazy Evolving Compression
Why ALEC?
In many environments, every bit counts:
- π°οΈ Satellite communications at a few kbps
- πΏ Battery-powered IoT sensors lasting years
- π Rural areas with limited satellite connectivity
- π Underwater acoustic links
- π Industrial networks with restricted bandwidth
ALEC addresses these challenges with an innovative approach: transmit only what has value.
Features
π¦₯ Lazy Compression
ALEC doesn't transmit all data β it first sends the decision, then details only if needed.
Without ALEC: [Complete data] βββββββββββββββββββββββΆ 1000 bytes
With ALEC: [Alert: anomaly detected] βββββββββββββΆ 12 bytes
[Details on demand] βββββββββββββββββββΆ 500 bytes (if requested)
π Evolving Context
Encoder and decoder build a shared dictionary that improves over time.
Week 1: "temperature=22.3Β°C" βββββββββββββββββββββββΆ 20 bytes
Week 4: [code_7][+0.3] ββββββββββββββββββββββββββββΆ 3 bytes
βοΈ Smart Asymmetry
Computational effort is placed where resources exist.
| Mode | Encoder | Decoder | Use Case |
|---|---|---|---|
| Standard | Light | Heavy | IoT sensors, drones |
| Reversed | Heavy | Light | Broadcast distribution |
π Priority Classification
Each data point receives a priority that determines its handling:
| Priority | Behavior | Example |
|---|---|---|
| P1 CRITICAL | Immediate send + acknowledgment | Fire alert |
| P2 IMPORTANT | Immediate send | Anomaly detected |
| P3 NORMAL | Standard send | Periodic measurement |
| P4 DEFERRED | On demand only | Detailed history |
| P5 DISPOSABLE | Never sent | Debug logs |
Use Cases
π Connected Agriculture
Field sensors monitor moisture, temperature, and nutrients. With ALEC, they run 10 years on battery by transmitting only alerts and anomalies.
π₯ Rural Telemedicine
A portable ultrasound in a remote area first sends "suspected cardiac anomaly" in 50 bytes. The remote doctor decides if they need the full image.
π Vehicle Fleets
500 trucks report their position. After a few weeks, the system knows the usual routes and only transmits deviations.
π°οΈ Space Observation
A satellite photographs Earth. It only sends significant changes compared to previous images.
β‘οΈ See all detailed use cases
Ecosystem
ALEC consists of multiple crates:
| Crate | Description | Features |
|---|---|---|
alec |
Core compression codec | Encoder, Decoder, Context |
alec-ffi |
C/C++ bindings | FFI interface, embedded targets |
alec-gateway |
Multi-sensor orchestration | Channel management, Frame aggregation |
alec-gateway[metrics] |
Entropy observability | TC, H_joint, Resilience R |
alec-complexity |
Anomaly detection | Baseline, Z-scores, Events |
Quick Install
# Core codec only
[]
= "1.2"
# C FFI (std)
[]
= "1.2"
# C FFI for embedded (bare-metal, no RTOS)
[]
= { = "1.2", = false, = ["bare-metal"] }
# C FFI for Zephyr RTOS
[]
= { = "1.2", = false, = ["zephyr"] }
Quick Start
Prerequisites
- Rust 1.70+ (encoder and decoder)
- Or: C compiler (embedded encoder only via
alec-ffi)
Installation
First Example
use ;
β‘οΈ Complete getting started guide
Embedded / no_std
ALEC supports embedded targets from version 1.2.0. The alec-ffi crate provides C bindings with three feature tiers:
Feature comparison
| Feature | Allocator | Panic handler | Target |
|---|---|---|---|
std (default) |
System | System | Linux, macOS, Windows |
no_std |
User-provided | User-provided | Any embedded |
bare-metal |
embedded-alloc (8KB heap) |
loop {} |
Bare-metal (no RTOS) |
zephyr |
Zephyr k_malloc/k_free |
loop {} |
Zephyr RTOS |
Bare-metal (no RTOS)
= { = "1.2", = false, = ["bare-metal"] }
Zephyr RTOS
= { = "1.2", = false, = ["zephyr"] }
Note on target selection for Zephyr: Use
thumbv8m.main-none-eabi(noteabihf). Zephyr's nRF91 toolchain compiles innofpmode β using thehfvariant causes an ABI mismatch at link time.
CMakeLists.txt integration (Zephyr)
add_library(alec_ffi STATIC IMPORTED GLOBAL)
set_target_properties(alec_ffi PROPERTIES
IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/libalec_ffi.a
)
target_include_directories(alec_ffi INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}/include
)
# Do NOT use --whole-archive β causes premature static initialisation before Zephyr heap is ready
Add a critical_section.c to your Zephyr app:
static unsigned int cs_irq_key;
void
void
Validated embedded platforms
| Platform | SoC | Feature | Status |
|---|---|---|---|
| Nordic nRF9151 SMA-DK | Cortex-M33 | zephyr |
β Validated |
| Generic Cortex-M33 | thumbv8m | bare-metal |
β Builds |
β‘οΈ See the full NB-IoT demo
Documentation
Core Documentation
| Document | Description |
|---|---|
| Architecture | System design and ADRs |
| Getting Started | Getting started guide |
| Protocol Reference | Protocol specification |
| Security | Security considerations |
| FAQ | Frequently asked questions |
Module Documentation
| Document | Description |
|---|---|
| Gateway Guide | Multi-sensor orchestration |
| Metrics Guide | Entropy and resilience computation |
| Complexity Guide | Baseline learning and anomaly detection |
| Configuration | Complete configuration reference |
| Integration | Integration patterns |
Performance
Results on reference dataset (temperature sensor, 24h, 1 measurement/min):
| Metric | Without context | After warm-up | Target |
|---|---|---|---|
| Compression ratio | 0.65 | 0.08 | < 0.10 β |
| P1 Latency | 45ms | 42ms | < 100ms β |
| Encoder RAM | 12KB | 28KB | < 64KB β |
Roadmap
- v1.0 β Production ready β
- v1.2.0 β no_std support β
- v1.2.1 β bare-metal embedded (Cortex-M) β
- v1.2.3 β Zephyr RTOS support β
- v1.3 β RIOT OS support
- v1.4 β FreeRTOS support
β‘οΈ See the complete roadmap
Contributing
Contributions are welcome! See:
- CONTRIBUTING.md β Contribution guide
- prompts/ β Templates for features, bugfixes, etc.
- examples/ β Example workflows
License
ALEC is dual-licensed:
Open Source (AGPL-3.0)
Free for open source projects, research, and personal use.
[]
= "1.2"
Commercial License
For proprietary use without open-source obligations. Starting at $500/year for startups.
See LICENSE for details.
Compact fixed-channel mode (v1.3.5+)
For constrained LoRaWAN deployments with hard payload ceilings (e.g. 11 bytes), ALEC now supports a compact fixed-channel wire format:
- 4-byte header (sequence u16 + context_version u16)
- 2-byte bitmap (2 bits per channel, up to 64 channels)
- No name_ids, no device timestamp
- Marker byte: 0xA1 (data) / 0xA2 (keyframe)
- Steady-state avg: ~8B for 5 channels
- Fits in 11-byte LoRaWAN payload ceiling
Packet loss recovery
ALEC is a stateful differential codec. To handle lossy networks:
- Periodic keyframe every N transmissions (default 50) forces Raw32 for all channels β automatic recovery
- Sequence gap detection triggers context reset
- LoRaWAN downlink smart resync: send 0xFF command to request immediate keyframe, reducing worst-case drift from NΓinterval to 1Γinterval
Context persistence
For server-side decoder persistence across restarts:
alec_decoder_export_state()β ALCS binary format (~1.5 KB for 5 channels)alec_decoder_import_state()β restore decoder- Bit-exact round-trip verified
- CRC32 checksum, format-versioned (ALCS v1)
Multi-architecture support
Verified bare-metal builds:
| Target | Use case | .text (ALEC) |
|---|---|---|
thumbv7m-none-eabi |
Cortex-M3 | ~55 KB |
thumbv7em-none-eabi |
Cortex-M4 | ~55 KB |
thumbv7em-none-eabihf |
Cortex-M4F | ~56 KB |
thumbv6m-none-eabi |
Cortex-M0+ | ~53 KB |
Note: final linked size with --gc-sections will be
significantly smaller.
Acknowledgments
ALEC draws inspiration from:
- NASA error-correcting codes (turbo codes, LDPC)
- Dictionary compression (LZ77, LZ78)
- Efficient IoT protocols (CoAP, MQTT-SN)