Cruller: A Production-Focused Bun Runtime Ported to Zig 0.16
Cruller: A Production-Focused Bun Runtime Ported to Zig 0.16
Cruller provides a minimal, production-focused JavaScript runtime by stripping Bun's development tooling and porting the core to Zig 0.16
Cruller is a fork of the last Zig-based release of Bun, specifically designed to serve as a lightweight production runtime rather than a general-purpose development environment. By removing non-essential subsystems, the project reduces the binary size and simplifies the build process for production JavaScript servers.
Core Functionality and Scope
Cruller retains the essential components required to run pre-built production JavaScript servers. It maintains support for:
- JavaScriptCore: The underlying engine.
- Bun.serve: The primary server implementation.
- HTTP/1-3 and WebSockets: Core networking protocols.
- Web APIs:
fetch, streams,Blob,Request, andResponse. - Static Serving: Ability to serve static files.
- Module Resolver: Support for pre-built JavaScript modules.
To achieve its minimalism, Cruller intentionally removes the following development-oriented features:
- Package manager and bundler/transpiler.
- Shell and test runner (
bun test). - Most CLI dispatch mechanisms.
- N-API, SQL clients, and archive support.
Technical Implementation and Zig 0.16 Migration
The migration to Zig 0.16 involved separating the runtime from Bun's original patched Zig build integration. The project now utilizes a vanilla Zig 0.16 build graph and includes compatibility shims for APIs that changed between Zig 0.15 and 0.16.
To ensure release builds remain portable, Cruller implements a generated-code embedding module, which prevents the runtime from needing to load generated JavaScript from the build directory at runtime.
Performance and Size Metrics
Measurements on Linux x64 compared to the official Bun 1.3.14 binary show a significant reduction in footprint:
| Metric | Official Bun 1.3.14 | Cruller (ReleaseFast stripped) | Difference |
|---|---|---|---|
| Binary Size | 88.5 MiB | 73.0 MiB | ~18% Reduction |
| V8 Crypto Benchmark | Parity | Parity | ~2% variance |
Future Roadmap and Design Goals
The maintainer intends for Cruller to be used as a production supplement to the full Bun runtime. Development would occur in the full Bun environment, with deployment occurring on the lightweight Cruller fork.
Planned enhancements include:
- Enhanced Networking: Strengthening HTTP/2 and HTTP/3 support.
- Native Integration: Adding native ZMQ plugins.
- Memory Management: Implementing a dynamic memory controller via a separate QuickJS-based control plane for complex memory policies.
- Embeddability: Packaging the engine as a dynamic library with a clean
.ziginterface for easier integration into other Zig applications.
Community Discussion and Critiques
The project has sparked debate within the developer community regarding the viability of using different runtimes for development and production.
"I don't think I would deviate my development runtime from my production runtime so significantly. The chance for behavior that only rears its head in production is too high for my liking."
Other critiques focused on the project's history and design choices, with some users questioning the value of stripping a codebase that was previously described by Zig's creator, Andrew Kelley, as containing poor Zig practices. There were also concerns regarding the pruning of the original git history in the fork, which some argue removes critical attribution and context.
Current Status
Cruller is currently a work in progress. It supports Linux x64 and Zig 0.16.0. Basic smoke tests for Bun.serve and fetch() currently pass, along with CJS/ESM entrypoints and Node path tests.