coip — Columnar IP Database Format (.coi)
English | 简体中文
coip is a modern, open-source, read-only columnar IP database format (.coi) with a Rust toolkit and a zero-cgo pure-Go reader. It losslessly stores arbitrary structured IP→Record databases (including any MaxMind .mmdb file: GeoIP2/GeoLite2 City, Country, ASN, ISP, Enterprise, DB-IP, IPinfo, or custom CSV/JSONL feeds) at 4.7–4.9× smaller on-disk size, while providing microsecond random point-lookups and compile-once column projection.
Key Features
- 100% Lossless: Preserves all MMDB fields, numeric widths, IEEE-754
f64bit patterns,Nonevsfalse/0/""optionality, multi-language maps, and IPv6→IPv4 DAG alias semantics. - Self-Describing 6-Primitive Schema: No hardcoded GeoIP fields; supports arbitrary schemas, dynamic inspection, build-time
--keep-fields/--languagespruning, and compile-once Column Projection. - Two Tuned Profiles:
Compact(Zstd +Section 3: ZstdDicts+ZeroSkipDelta/LocalDictSplit): 4.75–4.90× smaller than.mmdb.UltraFast(pure-Rust LZ4): 3.34× smaller than.mmdb, 19.5 µs cold 5-field lookup, 1.15 µs warm 5-field lookup (1.7× faster thanmaxminddb), and 3.00M QPS across 8 threads.
- Zero-C Pure-Rust & Pure-Go Readers:
coip-readerdefaults to pure-Rustruzstd+lz4_flex(optionalzstd-cfeature);bindings/goprovides a standaloneCGO_ENABLED=0pure-Go COI v1.0 reader. - Open Binary Specification: Byte-level specification in
docs/SPEC.md(中文导读), detailed benchmark report indocs/BENCHMARKS.md(中文压测报告), and cross-language golden vectors intest-vectors/.
Real-World Benchmark (GeoIP2-City.mmdb, 672,963 unique records, 8 languages)
Measured on Intel Core i7-13700 (Windows x64, coip bench with zstd-c). Full section breakdown, ruzstd vs zstd-c, and Go benchmarks are in docs/BENCHMARKS.md.
| Format / Profile | File Size | Ratio vs MMDB | Cold 5-Field (serde) |
Warm 5-Field (1T) | Warm 8-Thread QPS |
|---|---|---|---|---|---|
MaxMind GeoIP2-City.mmdb (maxminddb 5-field) |
104.27 MB | 1.00× | 2.15–2.24 µs | 1.90–1.98 µs | 2.92–3.16M QPS |
MaxMind GeoIP2-City.mmdb (maxminddb full) |
104.27 MB | 1.00× | 3.00–3.53 µs | 2.59–2.88 µs | — |
coip Compact (Zstd + 4 ZstdDicts) |
21.95 MB | 4.75× | 103.2 µs | 1.26 µs (793K QPS) | 2.85M QPS |
coip Compact-Max (--zstd-level 19) |
21.30 MB | 4.90× | ~103 µs | ~1.26 µs | ~2.85M QPS |
coip UltraFast (pure-Rust LZ4) |
31.26 MB | 3.34× | 19.46 µs | 1.15 µs (871K QPS) | 3.00M QPS |
coip Country-only pruned (en, zh-CN) |
1.05 MB | 99.25× | 27.93 µs | 0.34 µs (2.91M QPS) | 5.89M QPS |
Workspace Layout
| Path | Description |
|---|---|
docs/SPEC.md / docs/SPEC.zh-CN.md |
Canonical COI v1.0 binary format specification (EN & ZH-CN) |
docs/BENCHMARKS.md / docs/BENCHMARKS.zh-CN.md |
Compression evolution, section breakdown, latency/QPS & architecture analysis |
crates/coip-format |
Header, Footer, Section Directory, Schema, Varint, CRC32C (no_std + alloc) |
crates/coip-builder |
Generic .coi builder, lossless .mmdb importer, LPM resolver, pruning, CSV/JSONL import |
crates/coip-reader |
mmap / &[u8] / File reader, sharded LRU caches, Column Projection, streaming serde |
crates/coip-cli |
CLI: coip convert | import | export | diff | lookup | query | inspect | verify | bench |
bindings/go |
Standalone pure-Go (CGO_ENABLED=0) COI v1.0 reader (中文文档) |
test-vectors/ |
Cross-language golden .coi test vectors (Compact + UltraFast) and expected JSON |
benches/ |
Criterion benchmark suite comparing coip-reader vs maxminddb |
CLI Quick Start
# Convert an MMDB file to .coi (Compact Zstd + ZstdDicts profile, 4.75x smaller)
# Convert with UltraFast profile (pure-Rust LZ4, 19.5 µs cold / 1.15 µs warm, 3.34x smaller)
# Build-time field/language pruning or .coi -> .coi repacking (no .mmdb needed!)
# Import any custom JSONL or CSV IP dataset (supports overlapping LPM CIDRs & IP ranges)
# Export a .coi database as canonical CIDR + JSONL (with optional projection)
# Diff two .coi databases (exact dual-stack IP additions, removals, and changes)
# Inspect schema, dictionaries, ZstdDicts, and section sizes
# Lookup / query an IP (full record, projected fields, pure --json, or Nushell-style --table)
# Exhaustively verify 100% field-by-field lossless equivalence against source MMDB
# Benchmark cold / warm / multi-threaded concurrent lookups vs maxminddb
Rust Library Example
See runnable examples in crates/coip-reader/examples/basic_lookup.rs and crates/coip-builder/examples/custom_db.rs:
Pure-Go Reader (bindings/go)
import coip "github.com/netkn001/coip/bindings/go"
r, err := coip.Open("GeoIP2-City.coi")
if err != nil
defer r.Close()
proj, _ := coip.CompileProjection("country.iso_code", "location.latitude", "location.longitude")
rec, found, err := r.LookupProjectedString("8.8.8.8", proj)
See bindings/go/README.md (简体中文) for full Go documentation.
License
MIT License — see LICENSE.