AI summary by TwinMind
I Made The Fastest JS Framework (please don't use it)
Theo - t3․gg
13m 15s
Initial Benchmark Context
- Previous SSR performance showdown video covered different JavaScript SSR solutions
- Night before big launch, got distracted by optimization idea due to ADHD brain
- Initially thought idea might be dumb but proved it could make SSR 5x faster
- Not using Bun initially (added later), not recommended for production
PostHog Sponsorship
- All-in-one product analytics suite
- Recommended for applications with user authentication/sign-in
- Features: analytics, session replay, feature flags, experiments
- Used for Pick Thing service and Upload Thing
- Cheap pricing, open source, self-hostable option
Traditional Benchmark Setup
- Fastify implementation was fastest before new solution
- Uses fastify-html package for HTML serialization
- Template string approach with sanitization via template functions
- Server code generates complex HTML page with hundreds of divs
- Math calculations applied to all elements with embedded styles
Core Problem Identification
- HTML generation work is CPU-intensive and blocking
- Runs on main thread, blocks other requests from resolving
- Making it async doesn't help - still single-threaded execution
- Until HTML generation completes, nothing else can happen
- Not IO-bound work (no database/network waits)
JavaScript Workers Solution
- JavaScript workers (not Cloudflare workers) as solution
- Workers are difficult to implement correctly
- Created worker pool approach vs single worker per request
Performance Testing Results
- Original fastify benchmark: ~1,200 requests/second
- Single worker per request: ~120 requests/second (10x slower due to spinup cost)
- Worker pool with 12 workers: ~5,000 requests/second (4x+ improvement)
- Testing with 1000 connections: connection refused
- Testing with 100 connections: slower due to maxing out cores/threads
- Optimal at 12 workers matching thread count
Bun Implementation
- Required significant changes due to Bun's JS standards compliance differences
- Worker file changes needed:
- postMessage as global instead of parentPort
- self.onmessage binding instead of parentPort.onmessage
- File must be accessed via worker, can't run directly
- Bun performance: 6,538 requests/second (vs 4,841 with Node)
- Expected bigger performance gap based on Bun's published benchmarks
- Bun's site shows 14,000 req/sec for React app rendering
Industry Validation
- Contacted Matteo (Fastify creator, Node contributor) about approach
- Matteo replied about launching something similar on September 24th
- Validation that approach aligns with industry direction
- Proud moment of independently arriving at same conclusion as benchmark creators
Real-World Performance Considerations
- Benchmark results don't meaningfully matter in production
- Database requests and IO operations are typical bottlenecks
- Raw HTML generation throughput rarely the limiting factor
- JavaScript servers spend more time on network/database waits
- Previous video covered why Node/Next.js benchmarks have limited real-world value
- Solution demonstrates JavaScript can achieve high performance when needed
