MindIR Compact (MIC)
MIC is a text-based, line-oriented format designed for minimal token usage when working with AI agents, git-friendly diffs, and deterministic serialization.
Design Goals
- 5.3x token reduction compared to JSON serialization
- 2.4x faster parsing than JSON (2.26 us vs 5.31 us)
- Git-friendly diffs with one node per line
- Stable IDs for safe patching operations
- Deterministic canonicalization for reproducible outputs
Benchmark Results
| Format | Tokens | vs JSON | Parse Speed | Annual Cost (1M IRs) |
|---|---|---|---|---|
| JSON | 278 | baseline | 5.31 us | $487 |
| TOML | 151 | 1.8x | 137.06 us | $264 |
| TOON | 67 | 4.1x | 2.67 us | $117 |
| MIC | 52 | 5.3x | 2.26 us | $91 |
MIC saves $396/year per million IR operations vs JSON at GPT-5.2 pricing ($0.00175/1K input tokens).
Format Overview
mic@1 # Version header S0 "input" # Symbol table T0 f32 # Type table (scalar) T1 [f32;3,4] # Tensor type (3x4 matrix) N1 const.i64 42 T0 # Node definitions N2 add N1 N1 T0 # Binary operation O N2 # Output marker
Line Types
| Prefix | Purpose | Example |
|---|---|---|
| mic@N | Version header | mic@1 |
| S<id> | Symbol definition | S0 "weight" |
| T<id> | Type definition | T0 [f32;B,128] |
| N<id> | Node definition | N5 matmul N3 N4 T1 |
| O | Output marker | O N5 |
| # | Comment | # Layer 1 |
Supported Operations
| Category | Operations |
|---|---|
| Constants | const.i64, const.f32, const.tensor |
| Arithmetic | add, sub, mul, div |
| Linear Algebra | matmul, dot, transpose |
| Reductions | sum, mean, sum_all, mean_all |
| Shape | reshape, squeeze, expand_dims, gather |
| Activations | relu, conv2d |
Type Syntax
# Scalar types T0 f32 T1 i64 T2 bool # Tensor types: [dtype;dim1,dim2,...] T3 [f32;3,4] # 3x4 matrix T4 [f32;B,128] # Batch x 128 (symbolic B) T5 [f32;?,?] # Dynamic shape
Example: Simple Neural Network
mic@1 # Types T0 [f32;B,784] # Input: batch x 784 T1 [f32;784,256] # Weight 1 T2 [f32;B,256] # Hidden layer T3 [f32;256,10] # Weight 2 T4 [f32;B,10] # Output # Nodes N0 param S0 T0 # Input N1 param S1 T1 # W1 N2 matmul N0 N1 T2 # x @ W1 N3 relu N2 T2 # ReLU activation N4 param S2 T3 # W2 N5 matmul N3 N4 T4 # hidden @ W2 O N5 # Output
Security Limits
The MIC parser enforces strict limits to prevent denial-of-service attacks:
- Input size: 10 MB maximum
- Node count: 100,000 maximum
- Shape dimensions: 32 maximum
- Interned strings: 100,000 maximum
Rust API
use mind::ir::compact::{emit_mic, parse_mic};
use mind::ir::IRModule;
// Parse MIC to IR
let module = parse_mic(mic_str)?;
// Emit IR to MIC
let mic = emit_mic(&module);
// Roundtrip is deterministic
assert_eq!(emit_mic(&parse_mic(&mic)?), mic);Learn More
See the full MIC specification at RFC-0001: MindIR Compact.