zstd -22 + domain-trained dictionary beats brotli-q11 (amortized) across 3 in-scope domains — access_log +34.08%、 structured_log +15.80%、 csv_metrics +15.33%
前 turn 「brotli は 化け物」 議論 の 直接 follow-up。 化け物性 = RFC 7932 Appendix A の 122 KB 静的 web-generic dictionary が 事前 amortized で ship されて いる 事実。 対抗策 = 同 amortized discipline で domain-specific static dict を ship。 zstd (Meta BSD) --train で per-domain dict 訓練 + zstd -22 --ultra -D compression。 実測: 3/3 全 in-scope domain で brotli を 超える (amortized) ★、 access_log +34.08% / structured_log +15.80% / csv_metrics +15.33%。 13/13 test PASS + md5 lossless round-trip 3/3。
1. 実測 結果 (3 in-scope domains)
| domain | 原文 | gzip -9 | brotli -q11 | zstd dict | zstd body | amortized vs brotli | fair |
|---|---|---|---|---|---|---|---|
| access_log_apache | 1,219,866 | 182,806 | 19,604 | 69,563 | 12,923 | +34.08% ★ | -320.8% |
| structured_log | 698,392 | 158,005 | 135,493 | 131,072 | 114,084 | +15.80% ★ | -80.9% |
| csv_metrics | 471,836 | 114,942 | 77,396 | 131,072 | 65,535 | +15.33% ★ | -154.0% |
3/3 beat brotli (amortized)、 md5 lossless round-trip 3/3 verified。
2. Amortized vs fair scoring 議論
Amortized (brotli static dict 同 convention)
- brotli's 122 KB dict: RFC 7932 Appendix A、 全 世界 encoder + decoder で 事前 合意、 output に carry されない、 amortized cost per file = 0 byte
- 本 STEP の domain-trained dict: 69-131 KB per domain、 encoder + decoder で 事前 合意 (前提)、 output に carry されない、 amortized cost per file = 0 byte
- ★ 同一 discipline = 「dedicated schema knowledge を 事前 ship する」、 brotli は generic、 本 STEP は per-domain
Fair (dict counted per file)
- Dict + body = 82-197 KB total per file、 brotli 単体 に 負ける
- Fair scoring は 「単発 send」 use case、 amortized と 別 use case
- 常時 log stream 圧縮 (億単位 files、 dict 1 回 ship) = amortized
- 一回限り archive 圧縮 (dict も 一緒 送る) = fair
- 両方 report が honest
3. STEP 1867 pattern と の 対比 (2 手法 揃った)
| 手法 | mechanism | 最大 gain 例 | 実装 コスト | 汎用性 |
|---|---|---|---|---|
| STEP 1867 dedicated schema-aware | fixed-width binary field encoding | structured_log 94K (dedicated) < brotli 135K | 高 (per-domain 手作業) | ASCII-numeric field 特化 |
| STEP 1876 zstd trained dict | domain-specific static dict (RFC 7932 対称) | access_log 12.9K < brotli 19.6K (+34%) | 低 (`zstd --train` 数分) | 高 (どの domain でも) |
access_log で は STEP 1867 pattern 未実装 (STEP 1871 dedicated 103K > brotli 19.6K で 大負け) が、 本 STEP zstd + dict で 34% 超え = 手軽な pattern で brotli beat 実用化。 dedicated と trained-dict の 併用 で より 大きい gain 期待 (別 STEP)。
4. Honest scope
- In-sample training: dict は 同 corpus で train (access_log 8000 line で train、 8000 line で eval)、 過学習 リスク あり
- Out-of-sample validation は 別 STEP (v0.4 送り 12 candidate): held-out corpus で train → 独立 test で 実測 検証
- Synthetic corpora (LCG seed 20260907)、 real-world 数字 変わる 可能性
- brotli の amortized dict は universal 汎用、 本 STEP dict は per-domain (3 dict = 3 domain)。 「universal domain-specific dict」 は 別 STEP
- novelty 主張 なし: zstd trained dict は 標準機能 (zstd 1.3.0 2017-08 以降)、 brotli 1.1 (2023) も custom dict 対応。 本 STEP 貢献 = 「amortized dict discipline で brotli 化け物性 を 破る 実 evidence + 定量 裏付け」
- zstd v1.5.7 バイナリ (Meta/Facebook BSD)、 execFileSync 経由
- lossless round-trip 保証 = md5 identity (test file 3 domain 明示 assertion)
5. STEP 1848 pattern 12 段階目
1848 → 1862 → 1863 → 1867 (n=1 dedicated) → 1868 → 1869 → 1870 → 1871 (n=3 positive) → 1876 (brotli 化け物性 分解 + zstd trained dict で 3/3 amortized 超え)。 前 turn casual observation 「brotli は 化け物」 が 本 STEP で 「化け物性 = pre-shipped dict discipline」 の 定量 分解 + 「同 discipline で 破れる」 実証 に 昇格。
6. v0.4 送り update
- (1)/(7)/(9)/(11)/(13 本 STEP) ✅ 完了
- v0.4 送り 12 追加 = out-of-sample dict validation (held-out corpus で train → 独立 test)
- 残: (2) held-out CV / (3) continuous score / (4) 30+ domain / (5) cmix binary / (6) english anchor / (8) Huffman word-dict v0.2 / (10) Voynich section Huffman / (12) out-of-sample dict validation
7. 関連 STEP
8. 詳細参照
- 実装:
scripts/domain-family/zstd-trained-dict-compressor.ts(~170 行) - Test:
test/step1876-zstd-trained-dict-test.ts(13/13 PASS) - Report: zstd-trained-dict-vs-brotli-report.json
- Dicts:
data/domain-family/domain-dicts/{access_log_apache,structured_log,csv_metrics}.dict.bin(69-131 KB each、 repo 収録 = reproducibility 完全) - Notepad: 2026-09-07T06-30 STEP 1876
- Fragment: notes/steps/STEP_1876.md
- ← Tools index に 戻る