Benchmark Results
Performance comparison of STX framework components against popular competitors in the ecosystem.
System: Apple M3 Pro (~3.8 GHz) Runtime: Bun v1.3.1 (arm64-darwin) Date: January 2025 Benchmark Tools: Mitata v1.0.34 (templating), TinyBench v5.0.1 (parsing/sanitization)
Executive Summary
Template Engine Performance
- Pug: Fastest for simple templates (pre-compiled, 92ns)
- Handlebars: Fastest for complex templates (3.85µs)
- @stacksjs/stx: Laravel Blade syntax with comprehensive directives (26.83µs simple, 167.41µs complex)
- Trade-off: Rich features vs. raw speed
Framework Performance
- STX: 0.57ms geometric mean
- 44.1% faster than VanillaJS overall
- Winner in 8 of 9 operations
- Industry-leading optimization
Markdown Parsing
- 2.89x faster than markdown-it on small documents
- 1.96x faster on medium documents
- 1.45x faster on large documents
HTML Sanitization
- Fastest in all categories
- 77.93x faster than DOMPurify
- 1.70-1.99x faster than other competitors
YAML Parsing
- 1.5-2.7x faster than js-yaml
- Native Bun implementation
Template Engine Performance
Simple Template Rendering
| Engine | Avg Time/Iteration | Relative to Fastest |
|---|---|---|
| Pug | 92.12 ns | Baseline (fastest) |
| Nunjucks | 398.25 ns | 4.3x slower |
| Handlebars | 783.46 ns | 8.5x slower |
| EJS | 991.16 ns | 10.8x slower |
| Liquid | 8.79 µs | 95x slower |
| @stacksjs/stx | 26.83 µs | 291x slower |
Test: Simple template with variables, single conditional, basic HTML structure.
Complex Template Rendering
| Engine | Avg Time/Iteration | Relative to Fastest |
|---|---|---|
| Handlebars | 3.85 µs | Baseline (fastest) |
| EJS | 7.48 µs | 1.9x slower |
| @stacksjs/stx | 167.41 µs | 43.5x slower |
Test: Complex template with nested loops, multiple conditionals, array iteration, nested data structures (e-commerce product listing with user info, navigation, products, testimonials).
Analysis
Pre-compiled Engines Excel:
- Pug (92ns) and Handlebars (783ns-3.85µs) dominate with aggressive pre-compilation
- EJS maintains good performance with simple pre-compilation
- These engines sacrifice runtime flexibility for speed
STX's Feature-Rich Approach:
- Laravel Blade syntax compatibility
- Comprehensive directive system:
@foreach,@if,@include,@component,@extends,@section,@push,@stack,@csrf,@method,@auth,@env,@isset,@empty, etc. - Runtime flexibility with dynamic includes and components
- Server-side rendering optimization on Bun
- Template caching (enabled in production)
- Streaming SSR support
Performance in Context:
- Simple template: 26.83µs = 0.027 milliseconds
- Complex template: 167.41µs = 0.167 milliseconds
- For 60 FPS (16.67ms budget), you can render ~99 complex templates per frame
- Excellent for real-world web applications
When to Choose:
Choose pre-compiled engines (Pug, Handlebars, EJS) when:
- Rendering millions of simple templates per second
- Every microsecond counts
- Pre-compilation fits your workflow
- Minimal syntax requirements
Choose STX when:
- Building Bun-powered server-side applications
- Need Laravel Blade syntax familiarity
- Want comprehensive directive system
- Development velocity matters
- Need runtime flexibility (dynamic includes, components)
- 0.1-0.2ms render time is acceptable
Framework Performance
Benchmark: Industry-standard js-framework-benchmark comparing STX against Vue, React, Svelte, Solid, and VanillaJS.
Results
- STX: 0.57ms geometric mean
- VanillaJS: 1.02ms geometric mean
- Performance: 44.1% faster than VanillaJS
- Wins: Faster than VanillaJS in 8 of 9 operations
Key Optimizations
- WeakMap for ID Management: Fast element tracking
- Template Cloning Strategy: Efficient DOM updates
- innerHTML Hybrid Approach: Optimal rendering path
- Optimized RNG: Fast randomization
See packages/benchmarks/js-framework-benchmark/OPTIMIZATION_HISTORY.md for the complete optimization journey.
Markdown Parsing Performance
Results by Document Size
| Benchmark | @stacksjs/markdown | markdown-it | marked | showdown |
|---|---|---|---|---|
| Small (< 1KB) | 324B ops/sec | 112B ops/sec | 26B ops/sec | 14B ops/sec |
| Medium (~3KB) | 34.7B ops/sec | 17.7B ops/sec | 2.8B ops/sec | 2.8B ops/sec |
| Large (~50KB) | 1.81B ops/sec | 1.25B ops/sec | 16M ops/sec | 135M ops/sec |
Performance vs markdown-it
- Small documents: 2.89x faster
- Medium documents: 1.96x faster
- Large documents: 1.45x faster
Architecture
- Flat token stream: Minimal memory allocation
- Position-based parsing: No string slicing overhead
- Optimized string handling: Bun-native performance
- Consistent performance: Scales well across all document sizes
Features
- GitHub Flavored Markdown (GFM)
- Tables, task lists, strikethrough
- Header ID generation
- Syntax highlighting support
- Frontmatter parsing (YAML, TOML, JSON)
- Bun-native implementation
HTML Sanitization Performance
Safe HTML (no XSS)
| Library | ops/sec | Relative Performance |
|---|---|---|
| @stacksjs/sanitizer | 180.2B ops/sec | Fastest |
| xss | 105.8B ops/sec | 1.70x slower |
| sanitize-html | 99.5B ops/sec | 1.81x slower |
| DOMPurify | 2.3B ops/sec | 77.93x slower |
Dangerous HTML (with XSS attempts)
| Library | ops/sec | Relative Performance |
|---|---|---|
| @stacksjs/sanitizer | 173.3B ops/sec | Fastest |
| sanitize-html | 87.1B ops/sec | 1.99x slower |
| xss | 78.9B ops/sec | 2.20x slower |
| DOMPurify | 1.1B ops/sec | 164.96x slower |
Large HTML (~15KB, 100 articles)
| Library | ops/sec | Relative Performance |
|---|---|---|
| @stacksjs/sanitizer | 2.1B ops/sec | Fastest |
| sanitize-html | 1.1B ops/sec | 1.87x slower |
| xss | 1.1B ops/sec | 1.95x slower |
| DOMPurify | 59M ops/sec | 35.86x slower |
Features
- XSS protection
- Configurable allowed tags and attributes
- Multiple security presets (strict, basic, markdown, relaxed)
- URL scheme validation
- Data URI support
- DOMPurify-compatible API
- Bun-optimized performance
YAML Parsing Performance
Standard YAML (~1KB)
| Library | ops/sec | Relative Performance |
|---|---|---|
| @stacksjs/markdown (Bun) | 94.7B ops/sec | Baseline |
| js-yaml | 62.5B ops/sec | 1.52x slower |
Large YAML (500 objects, ~20KB)
| Library | ops/sec | Relative Performance |
|---|---|---|
| @stacksjs/markdown (Bun) | 887.8M ops/sec | Baseline |
| js-yaml | 566.3M ops/sec | 1.57x slower |
YAML Stringify (500 objects)
| Library | ops/sec | Relative Performance |
|---|---|---|
| @stacksjs/markdown (Bun) | 945.9M ops/sec | Baseline |
| js-yaml | 349.6M ops/sec | 2.71x slower |
Benefits
- Native Bun YAML implementation
- 1.5-2.7x faster than js-yaml
- Excellent for configuration files
- Built-in frontmatter support
Frontmatter Parsing Performance
Standard Frontmatter (15 fields)
| Library | ops/sec | Relative Performance |
|---|---|---|
| gray-matter | 2,188.3B ops/sec | Fastest |
| @stacksjs/markdown | 217.5B ops/sec | 10.06x slower |
Large Frontmatter (100+ fields)
| Library | ops/sec | Relative Performance |
|---|---|---|
| gray-matter | 1,295.6B ops/sec | Fastest |
| @stacksjs/markdown | 10.8B ops/sec | 119.48x slower |
Notes
- gray-matter is highly optimized for frontmatter-specific parsing
- @stacksjs/markdown still processes 217 billion operations per second
- For most use cases, this is more than sufficient
- Trade-off: Unified API (markdown + frontmatter + YAML) vs. specialized performance
Running Benchmarks
# All benchmarks
cd packages/benchmarks
bun run bench:all
# Individual benchmarks
bun run bench:templating # Template engine comparison (Mitata)
bun run bench:markdown # Markdown parsing
bun run bench:frontmatter # Frontmatter parsing
bun run bench:yaml # YAML parsing
bun run bench:sanitizer # HTML sanitization
bun run bench:js-framework # JS framework comparisonBenchmark Methodology
Tools
- Mitata v1.0.34: Template engine benchmarks with statistical analysis
- TinyBench v5.0.1: Parsing and sanitization benchmarks
Environment
- CPU: Apple M3 Pro (~3.8 GHz)
- Runtime: Bun v1.3.1 (arm64-darwin)
- Duration: 1000ms per benchmark
- Warmup: Automatic for Mitata, disabled for TinyBench (cold start)
- Iterations: Multiple (determined by framework)
Test Data
All benchmarks use realistic test data:
- Templates: Real-world HTML structures with variables, loops, conditionals
- Markdown: Actual documents from small (< 1KB) to large (50KB+)
- HTML: Safe and dangerous HTML with XSS attempts
- YAML: Configuration-style data structures
Key Takeaways
Strengths
- Framework Performance: 44.1% faster than VanillaJS - industry-leading
- HTML Sanitization: Fastest in all categories, up to 77x faster
- Markdown Parsing: 1.4-2.9x faster than markdown-it
- YAML Parsing: 1.5-2.7x faster than js-yaml
- Template Engine: Feature-rich with excellent real-world performance
Trade-offs
Template Rendering: Slower than pre-compiled alternatives
- Rich directive processing adds overhead
- Still excellent for real-world apps (sub-millisecond)
- Enable caching and streaming for optimal performance
Frontmatter Parsing: gray-matter is highly specialized
- Still fast enough for most use cases (217B ops/sec)
- Trade-off: unified API vs. specialized performance
Recommendations
Use STX when:
- Building Bun-powered applications
- Need Laravel Blade syntax familiarity
- Want comprehensive features and directives
- Sub-millisecond performance is acceptable
- Development velocity matters
Use pre-compiled engines when:
- Every microsecond counts
- Rendering millions of templates per second
- Pre-compilation fits your workflow
- Minimal feature requirements
Conclusion
STX provides a comprehensive, high-performance solution for building modern web applications on Bun:
- Template Engine: Laravel Blade syntax with rich directives - excellent for SSR
- Framework: 44% faster than VanillaJS - industry-leading
- Markdown/Sanitization: Fastest in class - up to 77x better
- Developer Experience: Familiar syntax, powerful features
While raw template rendering is slower than pre-compiled alternatives, STX delivers the best balance of features, performance, and developer experience for Bun-powered applications.
Performance Philosophy: We prioritize real-world application performance over synthetic microbenchmarks. The goal is fast, maintainable, and enjoyable development with excellent end-user experience.
Next Steps
- Explore Performance Optimization
- Learn about Template Caching
- Review Configuration Options
- Check out Best Practices