building @bunjavascript at @anthropicai. formerly: @stripe (twice) @thielfellowship. high school dropout. npm i -g bun

San Francisco, CA
People frequently ask: > How is Bun sustainable? If I bet my company’s tech stack on Bun, will Bun still be around in a few years? We didn’t have a great answer to this question, until today
265
143
4,742
1,368,622
i genuinely think good AOT JS/TS with full ecosystem compatibility would be the most exciting thing to happen to JavaScript since Node
58
23
988
61,408
the knock on server-side JS has always been that you only use it because you already know it. rEaL enGiNeeRs use Go or RuSt LLMs know every language so that doesn't matter anymore, but the substance behind that knock is still true - JS uses more memory and CPU
5
151
11,330
however, LLMs are also really good at writing compilers. so instead of you rewriting your app in another language, what if we just rewrite the compiler to make JS/TS perform competitively with Go and Rust then rewriting your app might not be worth it, even if it’s easy
10
256
10,546
this was my 3rd attempt at Bun AOT. the first two were before `bun check`, and performed worse than the JIT. it used bytecode instead of typescript types. binaries were sometimes 1 GB lol trying attempt 4 now. doesn’t work yet
32
3
513
35,446
Why are there like six parsing passes? Why does the trimmer think Bun.Archive is in use when you have a property named “Archive” somewhere? The results are exciting, but these questions sound like a bug farm.
2
68
5,988
I want this to be good. So another implementation, with a more refined design seems worth it. But the same underlying idea - TypeScript types -> IR as the starting point. sound types when proven, predictions, or unknown
3
51
4,132
In the next version of Bun bun check gets 1.7x - 7x faster
58
26
1,235
51,259
Here's a little how Bun AOT currently works (and may still change a lot): 1. bun build --compile --aot <script> 2. `bun check` type-checks but allows untyped code 3. Typed IR 4. Optimization passes 5. JavaScriptCore's B3 compiler runs 6. ARM64/x64 machine code (continued)
33
8
431
28,088
JSON.stringify's fast path for typed objects makes JSON.stringify 2.2x faster in this benchmark. Untyped objects or typed objects with extra properties fallback to the generic JSON.stringify
3
33
3,952
RegExp literals get compiled ahead of time
43
3,578
A year ago, I would've said a linter, a formatter and a type checker were too ambitious for Bun. But for ahead of time compiled TypeScript to have a shot at being something people use, it will need integrated tooling.
54
16
1,068
102,295
A Prettier-compatible formatter, builtin to Bun.
In the next version of Bun `bun fmt` is a 320x faster Prettier alternative Passes 99% of Prettier's test suite & supports 20 languages
3
2
113
12,377
A TypeScript-compatible type checker, builtin to Bun.
In the next version of Bun `bun check` is a TypeScript type checker builtin to Bun (written in Rust)
4
2
86
9,790