-
Notifications
You must be signed in to change notification settings - Fork 3.1k
JSZip runs very slowly when called from a Bun.serve or node:http handler, but not when called from a CLI script (Node.js is unaffected) #11054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is very likely related to |
I have the same issue. Using Bun + Elysia and zipping a file in request handler. Bun 1.1.27 |
Fixed in Bun v1.2.8.
|
Fixed by @cirospaciari in #18599 |
@Jarred-Sumner, @dylan-conway, I just ran the original test again and I'm still seeing a ~200x slowdown with Bun 1.2.8 (also with 1.2.9) compared to Node.js. I'm running As before the CLI version is unaffected:
Whereas the version behind an HTTP server shows the discrepancy:
@Jarred-Sumner What test did you run to obtain those numbers? |
Looks like this was fixed on macos in v1.2.8, but not linux. Reopening |
Having the same issue in a SvelteKit project running on Windows. Running |
I can confirm this is now fixed on Linux in Bun v1.2.10. It should also be fixed on Windows, but have not manually verified this
|
@Jarred-Sumner Thanks for answering, but running |
@cabralpinto 1.2.10 is currently in canary and not released yet, but you can run |
@Jarred-Sumner Thanks! Can confirm the issue fixed on Windows in the canary version. |
What version of Bun is running?
1.1.8+89d25807f
What platform is your computer?
Linux 6.6.30_1 x86_64 unknown
What steps can reproduce the bug?
Using Bun with JSZip (https://www.npmjs.com/package/jszip) to operate on a zip within the context of a Bun.serve or node:http handler yields an enormous performance degradation that is neither present when running the same code with Bun as a CLI script, nor when using Node.js.
In short:
This was tested using the latest bun alpine container. However, the problem also appears when using an environment in which Bun was installed with
curl -fsSL https://bun.sh/install | bash -s "bun-v1.1.8"
and I'm pretty sure it also occurs within the context of the official bun lambda runtime (https://github.com/oven-sh/bun/blob/main/packages/bun-lambda/runtime.ts) when deployed to AWS Lambda (I don't have scripts to reproduce the issue in those contexts, but the simple case below should be enough to trigger it. Regardless, it's not specific to alpine).The issue can be reproduced by using the following script, which can be invoked with either
bun index.js
to run the standalone version, or by usingbun index.js serve
, which will start a server on127.0.0.1:8080
that can be poked with something like curl or wget to trigger the same code from the request handler:index.js
Which can be tested using the following hyperfine tests:
test.sh
Here's a docker oneliner to run the test script:
What is the expected behavior?
I would've expected the code in the request handler to run just as fast as the code in the standalone CLI version, probably faster because of the reduced overhead (since the runtime is already up and running).
What do you see instead?
The Bun request handler (this means both
Bun.serve
andnode:http
; the test script uses the latter, but the former performs similarly) appears to run orders of magnitude slower than the CLI version, an issue that isn't present when the code is run with Node.js.Test results:
test-cli.md
bun index.js
node index.js
test-server.md
wget -qO- http://127.0.0.1:8080/bun
wget -qO- http://127.0.0.1:8080/node
Additional information
The larger the zip file, the bigger the slowdown appears to be (~200x for a decently sized ~1MB zip, if I recall correctly). Similar results were achieved when poking the server with cURL, just to eliminate wget as a suspect. I don't have any code prepped to explicitly verify this, but I did run some other tests to confirm JSZip produces the same output in all of these cases/contexts, so it appears to be purely a performance issue.
I'm currently working around this issue by running the affected code in a child process using
Bun.spawnSync
- it's not pretty, but it works.The text was updated successfully, but these errors were encountered: