Skip to content

Releases: oven-sh/bun

Bun v0.1.11

07 Sep 19:56
Compare
Choose a tag to compare

To upgrade:

bun upgrade

To install:

curl https://bun.sh/install | bash
If you have any problems upgrading

Run the install script (you can run it multiple times):

curl https://bun.sh/install | bash

In Bun v0.1.11, web framework libraries built on Bun got faster

image

Benchmark: https://github.com/SaltyAom/bun-http-framework-benchmark
This was run on Linux
Image credit: @Kapsonfire-DE

Plugin API

Bun's runtime now supports a plugin API.

  • import and require .svelte, .vue, .yaml, .scss, .less and other file extensions that Bun doesn't implement a builtin loader for
  • Dynamically generate ESM & CJS modules

The API is loosely based on esbuild's plugin API.

This code snippet lets you import .mdx files in Bun:

import { plugin } from "bun";
import { renderToStaticMarkup } from "react-dom/server";

// Their esbuild plugin runs in Bun (without esbuild)
import mdx from "@mdx-js/esbuild";
plugin(mdx());

// Usage
import Foo from "./bar.mdx";
console.log(renderToStaticMarkup(<Foo />));

This lets you import yaml files:

import { plugin } from "bun";

plugin({
  name: "YAML",

  setup(builder) {
    const { load } = require("js-yaml");
    const { readFileSync } = require("fs");
    // Run this function on any import that ends with .yaml or .yml
    builder.onLoad({ filter: /\.(yaml|yml)$/ }, (args) => {
      // Read the YAML file from disk
      const text = readFileSync(args.path, "utf8");

      // parse the YAML file with js-yaml
      const exports = load(text);

      return {
        // Copy the keys and values from the parsed YAML file into the ESM module namespace object
        exports,

        // we're returning an object
        loader: "object",
      };
    });
  },
});

We're planning on supporting browser builds with this plugin API as well (run at transpilation time)

Reliability improvements

Node compatibility:

  • feat: implement native os module by @xhyrom in #1115
  • fix buffer.copy by @zhuzilin in #1113
  • fix buffer.slice(0, 0) by @zhuzilin in #1114
  • Add buffer.indexOf, includes and lastIndexOf by @zhuzilin in #1112
  • Add native EventEmitter by @zhuzilin in #1123
  • Support emit Symbol events in EventEmitter by @zhuzilin in #1129
  • add SlowBuffer by @zhuzilin in #1133
  • update minified url polyfill by @samfundev in #1132
  • Add pad back to base64 by @zhuzilin in #1140
  • fix mkdtemp by @zhuzilin in #1151
  • Fix Buffer.isEncoding 39dc989
  • Implement napi_add_finalizer f023b89
  • NAPI_MODULE_INIT() wasn't implemented correctly in Bun and that has been fixed
  • import assert and import process did not behave as expected (assert wasn't returning a function). This has been fixed
  • "node:module"'s createRequire function wasn't requiring non-napi modules correctly

macOS event loop internals moved to a more reliable polling mechanism:

  • setTimeout CPU usage drops by 50% c1734c6 (Before: 90%, After: 33% - still more work to do here)
  • on macOS, bun would sometimes hang due to race conditions (unrelated to network connection) if you ran fetch enough times in quick succession. The race conditions have been fixed.

More:

  • [bun:ffi] Fix crash with uint64_t 296fb41
  • [bun:ffi] Fix int16 / uin16 max 30992a8
  • Fix Request and Response in macros e0b35b3
  • Fix clearTimeout on Linux e6a1209

Performance improvements

Bun has a long-term commitment to performance. On macOS, React server-side rendering gets around 2x faster.

image

Coming up next in performance improvements: a new HTTP server implementation. Not far enough along for this release, but experiments are showing progress.

PRs

New Contributors

Full Changelog: bun-v0.1.10...bun-v0.1.11

Bun v0.1.10

19 Aug 07:49
Compare
Choose a tag to compare

To upgrade:

bun upgrade

To install:

curl https://bun.sh/install | bash
If you have any problems upgrading

Run the install script (you can run it multiple times):

curl https://bun.sh/install | bash

What's new

  • Fix a regression causing bun dev to not send HTTP bodies
  • Fix console.log printing [native code] for too many things 5eeb704
  • Fix crash in bun dev when used with Next.js e45ddc0
  • Fix bug with Buffer.compare d150a2f
  • Make TextDecoder 2.5x faster e3c2a95
  • Fix memory leak in WebSocket bdf7339
  • Make Request, Response and TextDecoder globals not read-only 0f45386

Full Changelog: bun-v0.1.9...bun-v0.1.10

Bun v0.1.9

18 Aug 08:49
Compare
Choose a tag to compare

To upgrade:

bun upgrade

To install:

curl https://bun.sh/install | bash
If you have any problems upgrading

Run the install script (you can run it multiple times):

curl https://bun.sh/install | bash

What's new

  • Numerous crashes fixed by @zhuzilin!! Incredible work.
  • [Linux] Improved event loop reliability and reduced CPU usage for concurrent/async IO (affects bun install and fetch() mostly)
  • Bun.serve gets about 20% faster outside of "hello world" benchmarks due to optimizing how Headers are copied/read and faster generated bindings
  • require("buffer") and require("process") now point to Bun's implementation instead of a browserify polyfill (thanks @zhuzilin)
  • Fixed a bug that would cause setTimeout or setInterval to not keep the process alive (thanks @zhuzilin)
  • Updated to latest WebKit
  • 6x - 10x faster ptr() in bun:ffi

JIT-optimized TextEncoder.encodeInto can be a 1.5x perf boost up to around a 5x perf boost

image

The hash() function in this microbenchmark calls ptr():

image

Internals

Bun learns how to JIT

DOMJIT is a JavaScriptCore API that gives 3rd-party embedders low-level access to the JIT compiler/assembler to optimize native functions and getters/setters. Safari leverages DOMJIT to make commonly-accessed properties like element.parentNode faster

Bun is beginning to use DOMJIT now, starting in two places:

To better support Bun's usecase, I extended DOMJIT to support Typed Array arguments, as well as added support for specifying more kinds of side effects that enable/disable optimizations:

Faster and more reliable JSC <> Zig bindings

At Bun's compile-time, Bun now code-generates C++ binding classes for JavaScript objects implemented in Zig. Previously, Bun mostly used the JavaScriptCore C API.

Using JavaScriptCore's C++ API improves performance and is important for making the garbage collector better aware of Bun's usage. But, writing bindings manually can be very repetitive.

Given a class definition in JavaScript like this:

define({
    name: "Response",
    construct: true,
    finalize: true,
    JSType: "0b11101110",
    klass: {
      json: {
        fn: "constructJSON",
      },
     // rest of the code
    },
    proto: {
      url: {
        getter: "getURL",
        cache: true,
      },

      text: { fn: "getText" },
      json: { fn: "getJSON" },
      arrayBuffer: { fn: "getArrayBuffer" },
      blob: { fn: "getBlob" },
      clone: { fn: "doClone", length: 1 },
     // rest of the code
    },
  })

Bun generates corresponding:

This approach is inspired by WebIDL bindings which both Safari and Chromium use.

More reliable event loop on Linux

This screenshot is with a simulated bandwidth limit and no throttling of max http connections

Previously, bun had a tendency to hang in situations like this

image

What's Changed

New Contributors

Full Changelog: bun-v0.1.8...bun-v0.1.9

Bun v0.1.8

11 Aug 08:18
Compare
Choose a tag to compare

To upgrade:

bun upgrade

To install:

curl https://bun.sh/install | bash
If you have any problems upgrading

Run the install script (you can run it multiple times):

curl https://bun.sh/install | bash

What's new

A huge thank you to @zhuzilin for all their help on this release. @zhuzilin fixed 4 crashes!

bun link lets you symlink a folder to node_modules. It works like npm link.

fs.copyFileSync gets 2x to 10x faster:

require.resolve works at runtime now instead of only build-time

image

WebSocket is more reliable now. Previously the garbage collector would attempt to free it when the socket was still open 🙉

bun:ffi's toBuffer and toArrayBuffer functions now support a function pointer to a destructor so that native code can perform cleanup without needing to go through a FinalizationRegistry.

console.log

TypedArray logs the value for the type (instead of in bytes 🙈)

image

console.log(MessageEvent ) is more useful now

image

More:

  • setInterval wouldn't cause the process to stay alive 😢 and now that is fixed thanks to @zhuzilin
  • Log error on unhandled rejected promises by @zhuzilin in #1010
  • Log error on uncaught exceptions in event loop
  • bun install gets a symlink backend, which you probably don't want to use in most cases. It's used internally if you do file:./ as a dependency, which some packages do
  • process.revision returns the git sha used to build bun

Bug fixes

  • build issue caused "Illegal instruction" error to return - that is fixed now
  • [wiptest] fix calling toBe in describe by @zhuzilin in #1000
  • Re-register setInterval to VM after completion by @zhuzilin in #1014
  • Fix segfault for query().all() with more than 64 properties by @zhuzilin in #1025
  • Update example Next app to 12.2 by @TiKevin83 in #1033
  • Fix static require by setting the state machine manually by @zhuzilin in #1034
  • #941 fix by @JL102 in #998

Typos:

Misc:

Full Changelog: bun-v0.1.7...bun-v0.1.8

bun v0.1.7

06 Aug 08:15
Compare
Choose a tag to compare

To upgrade:

bun upgrade

To install:

curl https://bun.sh/install | bash
If you have any problems upgrading

Run the install script (you can run it multiple times):

curl https://bun.sh/install | bash

What's new

bun init quickly start a new, empty project that uses Bun (similar to npm init). bun init is a new subcommand in bun.

bun install now supports private npm registries & scoped (authenticated) packages

Thank you @soneymathew for your help with this.

image

bun install now supports lifecycle hooks for project-level package.json (not dependencies)

image

It runs postinstall scripts for your app's package.json, but ignores dependencies lifecycle hooks. This lets you use husky, lint-staged, and other postinstall-dependent packages tools

More new stuff:

  • express is partially supported, thanks to @zhuzilin and @evanwashere. There is a lot more work to be done - it's not fast yet and it logs a spurious error on request, but it is better than not working
  • bun create now lets you specify a start command so that you can say how to run the program in the output
  • process.revision has the git sha that bun was built with

Breaking changes

  • bun install will invalidate the lockfiles on upgrade if it exists. Unfortunately, this is necessary to support private/scoped package installs

Bug fixes

  • Fix a handful of crashes that occurred in rare cases in Bun.Transpiler, bun:ffi and a couple other places thanks to @sno2
  • Buffer.isBuffer no longer checks that this is the Buffer constructor
  • Bun.Transpiler no longer does bun-specific transforms when it shouldn't
  • Make internal APIs that iterate through JS objects more reliable @sno2 in #974
  • Fix u32 jsNumber cast by @zhuzilin in #964
  • fix import in http polyfill by @zhuzilin in #973
  • fix path.normalize on ... by @zhuzilin in #966
  • allow setting status code in Response.redirect by @zhuzilin in #985
  • Fix for bearer tokens missing from request headers on bun install step by @soneymathew in #991
  • Fix of panic in threads while downloading scoped packages by @soneymathew in #992
  • feat(util): export util.TextDecoder by @xhyrom in #990
  • Fixed bugs in latin1 and binary encodings in bun's Buffer implementation

Misc:

  • fix(makefile) fix devcontainer rule by @zhuzilin in #957
  • refactor: create a high-level property iterator by @sno2 in #972
  • fix(makefile): mkdir DEBUG_OBJ_DIR before compiling bindings by @zhuzilin in #975
  • Convert landing page to zero-JS Next.js application. by @leerob in #945
  • benchmarks(sqlite): invalid northwind database url by @xhyrom in #989
  • Update README for development help by @JL102 in #982

New Contributors

Full Changelog: bun-v0.1.6...bun-v0.1.7

bun v0.1.6

01 Aug 23:29
Compare
Choose a tag to compare

To upgrade:

bun upgrade
If you have any problems upgrading

Run this:

curl https://bun.sh/install | bash

What's new

  • No more "Illegal Instruction" error on start for those using CPUs which don't support AVX/AVX2 instructions! Thanks to bun's new baseline builds, these are separate builds of bun for Linux x64 and macOS x64 which do not use AVX/AVX2 instructions. You can install with the install script. This was one of the most common issues people ran into.
  • Add util.TextEncoder by @soneymathew in #844
  • fix(ffi): double-free segfault with symbols object by @sno2 in #919
  • -profile builds of bun include debug symbols
  • Update bun-framework-next for Compatibility with Next 12.2+ by @TiKevin83 in #920

Thanks to upgrading WebKit:

Commits

  • doc: added an helper for the huge Makefile by @Sanix-Darker in #804
  • fix install script colors for light background by @alexkuz in #800
  • Fix mistake in Next.js Example README. by @AadiTheCodecerer in #827
  • feat: add .PHONY on makefile targets by @Sanix-Darker in #847
  • ci: add docker caching to ci workflows by @HarshCasper in #846
  • feat: added info, info_bod and success method to wrap type of messages by @Sanix-Darker in #845
  • [Bun.js] support for util.TextEncoder by @soneymathew in #844
  • fix(examples/hono): refine Hono example by @yusukebe in #773
  • Change bun-types to latest by @LoiLock in #766
  • fix(release): Remove the ${{}} from the if block in GHA by @rgoomar in #863
  • feat: clean/factorize ARGS in the Dockerfile by @Sanix-Darker in #839
  • Use 'ADD' instead of running wget to make docker compare checksums on… by @mikeswann in #864
  • Increasing test coverage for node compatibility for util by @soneymathew in #854
  • chore(installer): use this repository instead release-for-updater by @xhyrom in #582
  • fix(types): add missing types for WebSocket by @xhyrom in #578
  • Add 'scripts/nproc' helper script by @penberg in #623
  • Support for completion in Bash by @zombieleet in #403
  • #609 Don't truncate ascii buffers to 7-bit by @szatkus in #775
  • docs(macos): Improve MacOS Development Instructions by @rgoomar in #836
  • landing/docs: make Bun naming consistent by @holic in #906
  • chore(ci): add segfault label by @sno2 in #916
  • docs: fix broken ffi benchmark link by @xhyrom in #914
  • fix(ffi): double-free segfault with symbols object by @sno2 in #919
  • Update bun-framework-next for Compatibility with Next 12.2+ by @TiKevin83 in #920
  • fix(makefile): devcontainer install by @paperdave in #933
  • Fix/react accessibility by @chasm in #932
  • refactor(bunjs/bindings): code readability fix `functionLazyLoadStrea… by @ryanrussell in #926
  • chore: fix labeler by @xhyrom in #899
  • Fix: move bun, Webkit and zig urls from Jarred-Sumner to oven-sh. by @oransimhony in #944
  • chore: migrate deprecated @vscode/dev-container-cli by @kidonng in #912

New Contributors

Full Changelog: bun-v0.1.5...bun-v0.1.6

bun v0.1.5

23 Jul 02:11
Compare
Choose a tag to compare

To upgrade:

bun upgrade
If you have any problems upgrading

Run this:

curl https://bun.sh/install | bash

This release is mostly just bug fixes. There is also a Linux arm64 build available (not for Android arm64 yet, but this should work for raspberry pi's)

Bug fixes:

  • Fix require is not defined bug
  • Fix one of the reasons why bun install hangs
  • Fix segfault in console.log (double free) @sno2 in #793
  • Fix exception in "url" polyfill @SheetJSDev in #772
  • Fix(env_loader): Off by one error by @FinnRG in #668
  • Add node:http server polyfill (this is not optimized yet, do not expect good performance from this version) by @evanwashere in #572
  • Fix bun add @scoped/package @alexkuz in #760
  • Fix setting port in bun install with BUN_CONFIG_REGISTRY @SheetJSDev in #823

New features

Two new flags added to bun install:

	    --no-progress              	Disable the progress bar
	    --no-verify                	Skip verifying integrity of newly downloaded packages
  • Implement some of the missing stat functions in node:fs @sno2 in #807

Misc:

Other:

New Contributors

Full Changelog: bun-v0.1.4...bun-v0.1.5

Canary (dbd320ccfa909053f95be9e1643d80d73286751f)

22 Jul 08:28
0d4b4c4
Compare
Choose a tag to compare

This release of Bun corresponds to the commit: a5a0539

Bun v0.1.4

13 Jul 08:49
Compare
Choose a tag to compare

To upgrade:

bun upgrade
If you have any problems upgrading

Run this:

curl https://bun.sh/install | bash

Bug fixes

  • Fixed a GC bug with fetch(url) that frequently caused crashes
  • fix(env_loader): Ignore spaces before equals sign by @FinnRG in #602

Misc:

Typos, README, examples:

New Contributors

Full Changelog: bun-v0.1.3...bun-v0.1.4

bun v0.1.3

11 Jul 19:38
Compare
Choose a tag to compare

What's new:

  • alert(), confirm(), prompt() are new globals, thanks to @sno2
  • more comprehensive type definitions, thanks to @Snazzah
  • Fixed console.log() sometimes adding an "n" to non-BigInt numbers thanks to @FinnRG
  • Fixed subarray() console.log bug
  • TypedArray logs like in node now instead of like a regular array
  • Migrate to Zig v0.10.0 (HEAD) by @alexkuz in #491
  • console.log(request) prints something instead of nothing
  • fix performance.now() returning nanoseconds instead of milliseconds @Pruxis
  • update wordmark in bun-error @Snazzah

All the PRs:

New Contributors

Full Changelog: bun-v0.1.2...bun-v0.1.3