bun icon indicating copy to clipboard operation
bun copied to clipboard

Performance spikes with Bun.file

Open SwatDoge opened this issue 2 years ago • 5 comments

Version

0.1.5

Platform

Linux clemster-desktop 5.15.0-41-generic #44~20.04.1-Ubuntu SMP Fri Jun 24 13:27:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

What steps will reproduce the bug?

It is honestly as simple as calling Bun.file methods:

const file = Bun.file(file_path);
const text = await file.text();
const blob = await file.arrayBuffer();

How often does it reproduce? Is there a required condition?

The issue is quite random, but it seems to become more severe over time.

What is the expected behavior?

Bun is regularly able to get 0-5ms on file reads, I'd like to see it achieve this speed range consistently, without 500ms-4s spikes

What do you see instead?

I see 500ms-4s spikes, right after the same piece of code produces 0-5ms image

Additional information

  • I use a Hono webserver in the screenshots, although this hasn't caused any other performance issues.
  • I run my Linux on a dying harddrive

SwatDoge avatar Jul 25 '22 15:07 SwatDoge

Maybe that is restricted by the OS file descriptors for the old hard drive.

kerolloz avatar Jul 25 '22 15:07 kerolloz

Maybe that is restricted by the OS file descriptors for the old hard drive.

I'll give this a shot on windows ^

SwatDoge avatar Jul 25 '22 15:07 SwatDoge

After a lot of hastling with windows, I ended up using a virtual machine (which did use my ssd). Its much more consistent but the same issue is still there, getting worse over time at unacceptable levels:

https://youtu.be/aJrTtQqMsH4

SwatDoge avatar Jul 25 '22 18:07 SwatDoge

This might be a hard-drive issue, but there also is an event loop issue where the event loop may idle when it shouldn't https://github.com/oven-sh/bun/issues/490

If you're only using Bun.file() to send static content, you should instead use new Response(Bun.file(path)), as that will use an optimized syscall for HTTP and it should produce more consistent (and better) performance

Jarred-Sumner avatar Jul 25 '22 20:07 Jarred-Sumner

Bun.write() also seems to have this same problem.

jhmaster2000 avatar Jul 30 '22 03:07 jhmaster2000