Deno vs Bun: Performance comparison for file server

Mayank C
Tech Tonic

--

From v1.25, Deno has introduced a totally new HTTP server called flash. The flash server is still under the unstable umbrella. The flash server is limited to HTTP/1.1 only. There is no HTTP/2 support yet. Deno authors claim that the new server is significantly faster than the old server.

Bun is a new JavaScript / TypeScript runtime that suddenly appeared on the market. Literally sudden! Bundle, transpile, install and run JavaScript & TypeScript projects — all in Bun. Bun is a new JavaScript runtime with a native bundler, transpiler, task runner and npm client built-in. Bun uses the JavaScriptCore engine, which tends to start and perform a little faster than more traditional choices like V8. Bun is written in Zig, a low-level programming language with manual memory management.

Bun claims that they are roughly three times faster than Deno. Let’s find it out!

In this article, we’ll compare Deno’s new HTTP server with Bun’s HTTP server for file server use case.

Test setup

Environment

The performance comparison is executed on the following environment:

  • System: MacBook M1 with 16G of memory
  • Local: The SUT and tester are on the same system
  • Deno version: 1.25.0
  • Bun version: 0.1.10

Code

We’ve written a small HTTP server that parses the request URL, extracts the relative file path, and then sends the file back in the HTTP response.

Bun

const baseServePath = "./testdata";
const { file } = Bun;
export default {
port: 3000,
fetch(req) {
const filePath = baseServePath + (new URL(req.url)).pathname;
return new Response(file(filePath), {
headers: {
"content-type": "application/pdf",
},
});
},
};

Note about Bun: Bun comes with a simple file API that takes a file path as input and converts it to ReadableStream.

Deno

const baseServePath = "./testdata";Deno.serve(async (req) => {
const filePath = baseServePath + (new URL(req.url)).pathname;
const file = await Deno.open(filePath);
return new Response(file.readable, {
headers: {
"content-type": "application/pdf",
},
});
}, { port: 3000 });

Note about Deno: Deno’s open API returns a file object that contains a ReadableStream connected to the file.

Settings

The performance test is executed in following configurations:

  • 10 concurrent connections to run a total of 10K requests
  • 25 concurrent connections to run a total of 10K requests
  • 50 concurrent connections to run a total of 10K requests

Measurements

The following measurements are recorded for each test configuration:

  • Time taken
  • Requests per second
  • Minimum
  • 1st Quartile
  • Median
  • Mean
  • 3rd Quartile
  • Maximum
  • CPU usage
  • Memory usage

Results

A total of 10K requests are executed for each test configuration.

For ease of comparison, all the results are summarized graphically. Here are the 16 graphs covering each of the above measurement:

Conclusion

So, is bun two times faster? Not for this use case. The performance is almost the same! At higher concurrency, Bun uses much more memory than Deno.

--

--