tl;dr; adding --bytecode and --production to bun build --compile gives a marginal boost.
I have a CLI tool called gg2 which is written in TypeScript and using Bun compiled to a single executable binary that can be installed with Homebrew. It's fast. Only 17% slower than GitHub's Go-compile gh CLI. But can it get even faster?
I read about Bytecode Caching which is supposed to make the executable "dramatically improved". Hmm. Let's see. There's also the --production option, which according to Set NODE_ENV=production and enable minification. Not convinced it's doing much but let's try.
I compiled the binary 4 different ways:
bun build src/index.ts --target=bun --compile --outfile out/ggbun build src/index.ts --target=bun --compile --outfile out/gg-bytecode --bytecodebun build src/index.ts --target=bun --compile --outfile out/gg-production --productionbun build src/index.ts --target=bun --compile --outfile out/gg-bytecode-production --production --bytecode
Then I ran hyperfine like this:
hyperfine "./out/gg --version" "./out/gg-bytecode --version" "./out/gg-production --version" "./out/gg-bytecode-production --version" --warmup 6
The results are as follows:
| BINARY | TIME (ms, smaller is better) | SIZE (MB) |
|---|---|---|
| gg | 87 | 58 |
| gg-bytecode | 81 | 60 |
| gg-production | 82.4 | 55 |
| gg-bytecode-production | 79.6 | 60 |
(sorry for being terrible at using Excel to draw charts)
Conclusion
I'm skeptical. The hyperfine often complains about statistical outliers so you have to run it with warmup and re-run it till it doesn't complain.
One caveat with using --bytecode is that the compiled code is not re-usable across different versions of bun but I don't understand how that's applicable if it's a executable binary that is shipped outside of Bun.
I'm going to add --bytecode and --production to the next release of gg2.

Comments