Meld is a portable template compiler. Write once, compile once, execute anywhere.
Meld compiles templates into TEF (Template Execution Format)—a compact, language-agnostic bytecode that runs natively on Rust, Go, Java, Python, PHP, and beyond. No runtime parsing. No language-specific code generation. Just fast, portable template execution at 50K–80K ops/sec.
See RUNTIME_PERFORMANCE.md for runtime optimization
rationale, bytecode invariants, and benchmark guidance.
- Fast: Compiled templates execute at near-native speed (~50K–80K ops/sec)
- Portable: Same compiled template runs on Rust, Go, or any TEF-compatible runtime
- Lightweight: Minimal runtimes with zero parsing overhead at execution time
- Composable: Automatic template composition and pluggable helper functions
Compile a template:
use meld::compiler::Builder;
let template = r#"<h1>Hello {{ name }}!</h1>"#;
let mut builder = Builder::new();
builder.build(template.as_bytes())?;
let compiled = builder.compile()?;Execute compiled template:
use meld::runtime::Runtime;
let program = Runtime::new(&compiled, config)?;
let payload = serde_json::json!({"name": "World"});
runtime.run(&payload)?;
let output = runtime.output(); // "<h1>Hello World!</h1>"See examples/ for complete usage patterns in Rust and Go.
- Fast execution
- Portable execution format (TEF)
- Tiny runtimes
- Language-agnostic
- Framework-agnostic
- First-class HTML support
- Island architecture support
- Zero template parsing at runtime
Template
│
▼
+-------------+
| Compiler |
+-------------+
│
▼
Template Execution Format (TEF)
│
├──────────────┐
▼ ▼
Rust Runtime Go Runtime
│ │
└──────┬───────┘
▼
HTML/etc Output
Traditional template engines either interpret templates at runtime or generate language-specific source code.
Meld compiles templates into a portable execution format that can be executed by any compatible runtime regardless of implementation language.
- Linear instruction stream
- Stack-based expression VM
- Static HTML emitted by byte offsets
- Compile-time optimization
- Automatic template composition
- Pluggable helper functions
- Server components
- Island hydration support
- Portable runtime specification
meld/
├── src/
│ ├── compiler/
│ ├── runtime/
└── examples/
└── benches/
└── samples/
Meld aims to provide a common execution format for server-rendered templates in the same way that WebAssembly provides a common execution format for native code.
Templates are authored once, compiled once, and executed efficiently across multiple languages through TEF.
Performance comparison of Rust and Go runtimes executing identical compiled templates:
| Implementation | Throughput (ops/sec) | Latency (µs) |
|---|---|---|
| Go Runtime | ~100,000 | ~10 |
| Rust Runtime | ~56,000 | ~17 |
Benchmarks measure template execution throughput across varying payload sizes (10K–100K iterations). The Go runtime achieves approximately 60% higher throughput while maintaining consistent performance. Both implementations scale linearly with input size.
Benchmark methodology:
- Compiled template execution only (parsing excluded)
- Real-world payloads with object/array nesting
- Measured across 20 sample runs per configuration
Early development. The TEF specification and runtime are under active design and may change before the first stable release.