I have a Node.js data processing CLI script. Just files in and files out with no external APIs or database connections. I spent the weekend converting it to Bun. I love the dev experience. And it is faster. But I can't figure out why the uncompiled Typescript is running faster than the built JS. Here is my build command:
"build": "rm -rf ./dist/* && bun build --entrypoints ./src/index.ts ./src/index-batch.ts --outdir ./dist --target bun",
I also tried the --compile option and it ran 2x slower than Typescript.
Here is how I run the benchmarks. There are 8 CLI args but using a couple as examples. Batch processing uses Bun.spawn() to run index.ts (or index.js if compiled).
hyperfine 'bun src/index.ts --a a --b b'
hyperfine 'bun dist/index.js --a a --b b'
hyperfine 'bun src/index-batch.ts -a a --b b'
hyperfine 'bun dist/index-batch.js -a a --b b'
Any ideas on how this can be? My understanding is that Bun ignores Typescript signatures or strips them out and that is slightly slower because of it. Either way, I am looking for the fastest execution because I need to run millions of these jobs regularly.
Thanks!