We present StateSMix, a fully self-contained lossless compressor that couples an online-trained Mamba-style State Space Model (SSM) with sparse n-gram context mixing and arithmetic coding. The model is initialised from scratch and trained token-by-token on the file being compressed, requiring no pre-trained weights, no GPU, and no external dependencies. The SSM (DM=32, NL=2, approximately 120K active parameters per file) provides a continuously-updated probability estimate over BPE tokens, while nine sparse n-gram hash tables (bigram through 32-gram, 16M slots each) add exact local and long-range pattern memorisation via a softmax-invariant logit-bias mechanism that updates only non-zero-count tokens. An entropy-adaptive scaling mechanism modulates the n-gram contribution based on the SSM's predictive confidence, preventing over-correction when the neural model is already well-calibrated. On the standard enwik8 benchmark, StateSMix achieves 2.123 bpb on 1 MB, 2.149 bpb on 3 MB, and 2.162 bpb on 10 MB, beating xz -9e (LZMA2) by 8.7%, 5.4%, and 0.7% respectively. Ablation experiments establish the SSM as the dominant compression engine: it alone accounts for a 46.6% size reduction over a frequency-count baseline and beats xz without any n-gram component, while n-gram tables provide a complementary 4.1% gain through exact context memorisation. OpenMP parallelisation of the training loop yields 1.9x speedup on 4 cores. The system is implemented in pure C with AVX2 SIMD and processes approximately 2,000 tokens per second on commodity x86-64 hardware.
Figures & tables
System
Model type
Params
bpb
Speed
GPU
Self-cont.
Category
gzip (DEFLATE)
—
—
2.916
GB/s
—
✓
dictionary
xz (LZMA2)
—
—
1.989
10 MB/s
—
✓
dictionary
bzip2
—
—
2.321
50 MB/s
—
✓
BWT+Huffman
PAQ8px
context mixing
—
∼1.27
< 1 KB/s
—
✓
context mix
CMIX v21
LSTM + mixing
∼50 M
∼1.17
< 1 KB/s
optional
✓
context mix
NNCP v3 ‡
Transformer-XL
online
∼1.19
∼ 1 KB/s
optional
✓
online neural
Table 1: Lossless compressor landscape on enwik8 (100 MB). † Pre-trained model weights excluded from compressed size; must be pre-shared. ‡ Model weights stored in compressed output. “Online” = model trained from scratch on the compressed file; no pre-trained weights required.
Table 3: N-gram model parameters ( λ , α as in Eq. 10 ).
File
Bytes
bpb
xz
Δ
enwik8 1M
265,370
2.123
2.326
−8.7%
enwik8 3M
805,926
2.149
2.271
−5.4%
enwik8 10M
2,702,498
2.162
2.177
−0.7%
enwik8 (100M)
26,622,640
2.130
1.992
+6.9%
Table 4: Compression results on enwik8 excerpts. Δ : relative difference vs. xz (negative = StateSMix better).
Variant
Bytes
bpb
vs Full
Count only
1,571,738
4.191
+95.0%
N-gram + count
1,319,045
3.517
+63.6%
SSM + count
840,095
2.240
+4.2%
Full (all)
805,926
2.149
—
xz − 9e
851,572
2.271
+5.7%
Table 5: Ablation on enwik8 3M . Count: frequency prior only. N-gram: all n-gram tables, no SSM. SSM: Mamba only, no n-grams. Full: complete system.
Tokens seen
bpt
0
≈8.10 (cold start)
50,000
≈7.10 (SSM adapted)
500,000
≈6.90 (n-grams active)
3,000,000
≈6.83
10,000,000
≈6.83 (plateau)
29,700,000
6.813 (final)
Table 6: Online bpt progression during enwik8 (100 MB) compression.
Metric
Value
Notes
1-core speed
1.1K tok/s
400 KB/s
4-core speed
2.0K tok/s
700 KB/s
Compress time
∼ 4.2 h
4 cores
Peak RAM
6.1 GB
tables
N-gram tables
5.1 GB
9 × 16M
SSM params
11 MB
emb+head
Table 7: Speed and memory (enwik8 100 MB).
Order
k
λ
Hit rate
Fan-out
Bigram
1
0.15
>0.99
∼8
Trigram
2
0.10
∼0.85
∼6
4-gram
3
0.08
∼0.65
∼4
5-gram
4
0.06
∼0.45
∼3
6-gram
5
0.05
∼0.28
∼2.5
7-gram
6
0.04
∼0.14
∼2
Table 8: Qualitative per-order N-gram statistics on enwik8 10M . Hit rate: fraction of positions where the context key is found. Fan-out: mean number of distinct continuations per found context.