oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.19k stars 2.68k forks source link

Bun executes obfuscated code (target=browser) about 100x-600x slower than Node.js / ts-node / chromium browser console #13940

Closed ajfhs812 closed 1 day ago

ajfhs812 commented 5 days ago

What version of Bun is running?

1.1.27+267afa293

What platform is your computer?

Darwin 23.1.0 x86_64 i386

What steps can reproduce the bug?

  1. Go to https://pastebin.com/raw/xc1uanbE.
  2. Copy the raw code.
  3. Then, run it using:
    1. Bun:
      1. Paste it into a local JS file on your system.
      2. Run it via bun run <path_to_the_file>.js.
    2. bunx ts-node (similar steps as for Bun).
    3. Node.js (similar steps as for Bun).
    4. Browser's console (paste and run).

How did I get the code:

  1. Built source TS code using Bun (NODE_ENV=production bun build --minify --target=browser <PATH_TO_INPUT_FILE> --outfile=<PATH_TO_OUTPUT_FILE>).
  2. Then, received code from Bun uglified+mangled+minified with terser (NODE_ENV=production bunx terser <PATH_TO_INPUT_MINIFIED_FILE> --compress='drop_console=false,unsafe_arrows=true,unsafe_comps=true,unsafe_Function=true,unsafe_math=true,unsafe_symbols=true,unsafe_methods=true,unsafe_proto=true,unsafe_regexp=true,unsafe_undefined=true,unsafe=true,ecma=2020,hoist_funs=true,toplevel=true,pure_new=true,passes=10' --format='semicolons=true,beautify=false,ecma=2020,quote_style=1' --mangle 'eval=true,module=true,toplevel=true' --mangle-props --toplevel --comments=false --indent_level=1 --module -o <PATH_TO_OUTPUT_UGLIFIED_FILE>).
  3. Then, received code from terser obfuscated using obfuscator.io.

P.S: if you need the source code of some (or even each) of these steps, let me know.

What is the expected behavior?

  1. Bun should execute it fast enough.
  2. Bun should execute it maybe even more faster than Node.js, ts-node, browser's console, and other tools.

What do you see instead?

Bun is doing it much slower than expected.

Additional information

Benchmark results for that code I provided above:

Computer specs:

190n commented 5 days ago

Can you share the code before compiling and obfuscation?

github-actions[bot] commented 4 days ago

Hello @ajfhs812. Please provide a minimal reproduction using a GitHub repository, Replit, or CodeSandbox. Issues marked with needs repro will be closed if they have no activity within 3 days.