Runtime Mode
render() - Best for development and templates with dynamic inheritance. 2-4x faster than Nunjucks.
All benchmarks run on Mac Studio M1 Max, Bun 1.3.5.
Runtime Mode
render() - Best for development and templates with dynamic inheritance. 2-4x faster than Nunjucks.
AOT Mode
compile() - Pre-compile templates to JavaScript functions. 160x faster than Nunjucks.
| Benchmark | binja | Nunjucks | Speedup |
|---|---|---|---|
| Simple Template | 371K ops/s | 96K ops/s | 3.9x |
| Complex Template | 44K ops/s | 23K ops/s | 2.0x |
| Multiple Filters | 246K ops/s | 63K ops/s | 3.9x |
| Nested Loops | 76K ops/s | 26K ops/s | 3.0x |
| Conditionals | 84K ops/s | 25K ops/s | 3.4x |
| HTML Escaping | 985K ops/s | 242K ops/s | 4.1x |
| Large Dataset | 9.6K ops/s | 6.6K ops/s | 1.5x |
AOT compilation provides massive speedups by pre-compiling templates to optimized JavaScript functions:
| Benchmark | binja AOT | binja Runtime | Speedup |
|---|---|---|---|
| Simple Template | 14.3M ops/s | 371K ops/s | 39x |
| Complex Template | 1.07M ops/s | 44K ops/s | 24x |
| Nested Loops | 1.75M ops/s | 76K ops/s | 23x |
| Benchmark | binja AOT | Nunjucks | Speedup |
|---|---|---|---|
| Simple Template | 14.3M ops/s | 96K ops/s | 160x |
| Complex Template | 1.07M ops/s | 23K ops/s | 46x |
binja is built from scratch in TypeScript, optimized specifically for the Bun runtime. No legacy code or Node.js compatibility layers.
~70 common filters have inline implementations to avoid function call overhead:
// Instead of:filters['upper'](value)
// binja does:value.toUpperCase()This provides 10-15% speedup on filter-heavy templates.
Pre-compiling templates eliminates:
// Compile once at startupconst template = compile('<h1>{{ title|upper }}</h1>')
// Renders in microsecondsconst html = template({ title: 'hello' })binja’s AST is optimized for fast traversal and minimal memory allocation.
# Clone the repogit clone https://github.com/egeominotti/binja.gitcd binja
# Install dependenciesbun install
# Run benchmarksbun run benchmarkcompile() for static templatescache: true in Environmentenv.cacheStats() to optimize cacheMaxSizeimport { compile } from 'binja'
// Best practice: compile at startupconst templates = { home: compile(await Bun.file('./views/home.html').text()), user: compile(await Bun.file('./views/user.html').text()),}
// Sync rendering, extremely fastapp.get('/', () => templates.home({ title: 'Home' }))