AI summary by TwinMind

NextJS Was Too Slow...So He Made Bun??! Jarred Sumner & The Story Of Bun

Theo - t3․gg

1h 9m 35s

Jared's Programming Background

  • First language: Ruby (high school, ~10 years ago)
  • Chose Ruby on Rails because docs were easiest/most accessible
  • Built online tutoring box for teachers as first project
  • Dropped out of high school to get startup internship
  • Project-based learning approach - learns by doing, not reading

Origin Story: Game Development Frustrations

  • Built voxel multiplayer Minecraft-style game in browser using Next.js
  • Game featured large worlds, voice chat, live streaming to Twitch
  • Major pain point: slow iteration cycles (several seconds between code changes)
  • Slow feedback loops killed productivity, led to distractions
  • Initially tried esbuild + Next.js with plugins but didn't solve iteration speed

Early Bundler Experiments

  • First attempt: build bundler/transpiler to run entirely in browser using WebAssembly
  • Used File System Access API + service workers
  • Abandoned due to permissioning issues and unreliable service workers
  • CLI version initially slower than esbuild, then 3x faster after memory allocator changes

Language Choice: Why Zig

  • Evaluated multiple languages before Zig
  • Key factors:
    • Comptime: execute arbitrary code at compile time (not just text substitution macros)
    • Small binary sizes (vs Rust's ~300 lines assembly for hello world)
    • Dead code elimination capabilities
    • Clear code behavior without hidden control flow (no RAII)
    • Helpful Discord community (similar to early Rails docs experience)

Comptime Examples in Bun

  • Unicode bitset generation: 170KB bitset for identifier validation (2% performance boost)
  • VLQ encoding for source maps: generated at compile time vs copy-pasted numbers
  • Makes code more maintainable and self-documenting

Runtime Development Journey

  • Started as bundler/transpiler, evolved to need server-side rendering
  • Experimented with V8 isolate in Go (abandoned due to dual garbage collectors)
  • Chose JavaScriptCore over V8:
    • Faster startup times
    • Better regex performance
    • Direct integration with WebKit components (Headers, URL objects from Safari)
    • Comes with browser-tested implementations of web standards

Philosophy: Nothing Out of Scope for Performance

  • "Nothing should be out of scope if it means something is slowing down"
  • If SQLite client is bottleneck, build faster SQLite client
  • Bun FFI enables fast native code integration
  • Future: potentially import Rust/Zig files directly in JavaScript

Current Architecture & Features

  • JavaScript runtime + bundler + transpiler + package manager in one tool
  • Uses JavaScriptCore with custom optimizations
  • Macros: run arbitrary JavaScript at build time, inline results into AST
  • Custom readable stream type "direct" for 1.5-2x React SSR performance boost
  • Built-in file system router (currently Next.js focused, expanding)

Deployment & Production Vision

  • .bun file format: entire app + dependencies in single file with metadata
  • Future: self-contained executables (like .exe, not .jar)
  • Edge runtime builds with feature-based binary dead code elimination
  • Send file optimization for static assets
  • Single file deploys to Lambda/serverless platforms

Testing & Development Needs

  • Bun desperately needs more test coverage
  • Tests written in JavaScript using bun wiptest
  • Aggressive garbage collection in tests (gc() after nearly every line)
  • Path.normalize bug needs fixing
  • Built-in diffing library needed (none exists in Zig ecosystem)

Future Roadmap

  • Express support for API routes (prerequisite for broader Next.js support)
  • Vue, Angular framework support via loader API
  • Multi-threading with shared memory (inspired by JavaScriptCore blog post)
  • Built-in modules expansion (file system router, diffing, etc.)
  • Browser testing integration (embed test runner in headless browser)
  • Production profiling data collection for optimization

Performance Philosophy

  • Web APIs harder to optimize than custom APIs designed for performance
  • Bun will offer both standards-compliant and Bun-optimized APIs
  • Focus on real-world app profiling once production adoption grows
  • Single binary deployment eliminates complex toolchain coordination

Misconceptions & Community

  • Surprised by overwhelming positive response
  • 430+ people watching live stream
  • Not trying to compete with frameworks - wants frameworks to use Bun
  • Logo is a bun (steam bun), not an onion
  • Originally named after Kip's bunny named "Bundle"

How to Help

  • Write more tests in JavaScript using Bun's test runner
  • Can contribute without knowing Zig or building from source
  • GitHub sponsors link to be created
  • Tests run quickly despite aggressive GC calls

TwinMind

Get summaries like this for your own meetings

TwinMind takes notes in the background during meetings, lectures, and calls, then writes the summary for you.

Free plan to get started

No bot joins your calls

Phone, desktop & Chrome apps

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome

Your next meeting, summarized like this

TwinMind listens in the background and turns meetings, lectures, and calls into searchable notes you can chat with. Start free.

Available on phone, desktop & Chrome