Compile and run C in JavaScript
Bun v1.1.28 adds experimental `cc` in `bun:ffi`, which uses TinyCC to compile, link and relocate C in memory and generates inline wrappers that convert between JavaScriptCore values and C primitives with no dynamic dispatch. It is pitched as an alternative to N-API addons, which need node-gyp builds or prebuilt platform matrices and cost 7–15ns per call versus 2ns for the JavaScriptCore C++ API, and to WebAssembly, which cannot make system calls and must copy data across its isolated memory. Benchmarks show about 5ms to compile a small file and roughly 2ns of per-call overhead over native C. It suits glue code for C and system libraries such as ffmpeg or the macOS Keychain, not large projects needing Clang/GCC-level optimization.
Related posts
- Bun v1.1.29
Bun mediumAdept
Bun v1.1.29 adds N-API support to its `cc` C compilation feature, letting C code return JavaScript strings, objects and arrays, which also works for shared libraries loaded via `dlopen` in `bun:ffi`. A new `"buffer"` argument type in `bun:ffi` passes typed arrays to C with inline conversion instead of external calls, making a hash microbenchmark about 40% faster than wrapping with `ptr()` (48.6 ns vs 82.6 ns per call). The release also fixes 21 bugs, including axios proxying, bundling imported .wasm files, a symbol-reordering regression in `bun build`, `bun test` always updating snapshots, and missing system include directories for `cc`.
- Bun v0.1.9
Bun mediumAdept
Bun v0.1.9 starts using JavaScriptCore's DOMJIT API to JIT-optimize native functions, making `ptr()` in `bun:ffi` 6-10x faster and `TextEncoder.encodeInto` 1.5-5x faster. To get there, Bun extended DOMJIT to accept Typed Array arguments and to declare more kinds of side effects. Bun now code-generates C++ binding classes and ABI-checked Zig bindings from JavaScript class definitions, an approach inspired by WebIDL, replacing most use of the JSC C API. Other changes include a more reliable, lower-CPU event loop on Linux, about 20% faster `Bun.serve` through better `Headers` handling, native `buffer` and `process` modules, and numerous crash fixes.
- Bun v1.3.7
Bun mediumAdept
Bun v1.3.7 upgrades JavaScriptCore, which brings faster async/await (35%), Array.from, padStart/padEnd, array.flat and better ARM64 codegen using ccmp/ccmn chains. It also speeds up Buffer.from() with arrays by up to 50% and Buffer.swap16/swap64 by 1.8x and 3.6x through CPU intrinsics. New APIs include Bun.wrapAnsi (33–88x faster than the wrap-ansi npm package), native JSON5 parsing and imports, and Bun.JSONL with streaming parseChunk. For diagnostics there is Markdown CPU and heap profile output, --heap-prof heap snapshots and the node:inspector Profiler API. Compatibility fixes cover header case preservation in fetch, S3 presign options, bun pm pack lifecycle scripts, Indic grapheme clustering and Next.js 16 timer internals.
- Bun v1.1.19
Bun mediumAdept
Bun v1.1.19 enables JavaScriptCore's FTL JIT on Windows for the first time in nine years, making Object.entries about 20% faster and cutting Array.map overhead roughly in half. The release fixes 54 bugs: crashes with optional peer dependencies in bun install, non-recursive comma-expression folding that fixes stack overflows with aws-cdk-lib, nested TypeScript namespace transpilation, and memory leaks in new Request(request) and fs.readdir withFileTypes. It also fixes an AbortSignal issue where a BoringSSL option ignored TCP shutdowns on HTTPS. Other changes include restored Raspberry Pi 4 support, statically linked UCRT on Windows, preserved package.json indentation and .npmrc _auth support.
- Bun v0.3.0
Bun mediumAdept
Bun v0.3.0 focuses on stability and Node.js/Web API compatibility, cutting memory use 3-5x under load by scheduling garbage collection in coordination with the event loop and speeding up TextEncoder.encodeInto() 3x via simdutf. New Node.js APIs include node:child_process, process stdio streams, Error.captureStackTrace and fs streams, alongside automatic npm package installs on import when no node_modules exists. Other additions are a native Next.js-style FileSystemRouter, console as an AsyncIterable for reading stdin, threadsafe bun:ffi callbacks, new bun:test matchers with a faster toEqual(), and a long list of fetch, spawn and crash fixes.