a month ago
After switching to bun to run our express.js server our memory usage has been growing a lot, before it stayed at around 400MB but now its at 2x that at 800MB and climbing.
Any way to prevent this memory curve or do we need to switch back to using node?
Attachments
1 Replies
a month ago
Hey,
I have observed this sort of memory growth with Bun in the past. Bun is still a pretty young language and is not yet nearly as mature or highly optimized as Node.js, especially with big frameworks like Express. The spike in memory you're observing with Bun might be attributed to its process of garbage collection not being highly optimized yet.
A few things you can try before switching back to Node:
Please ensure you’re using the latest Bun version, as they release updates resolving memory issues frequently.
You can also try running a minimal Express app with Bun and see if the memory still increases. If not, then it could just be your app or your middleware that's causing it.
Use profiling with Bun’s profiling tools or external profilers to find any leaks or large objects.
Test whether you can manually invoke Garbage Collection or adjust Bun's GC parameters (even though choices may be limited).
So if all this fails and the memory keeps climbing, it is completely reasonable to switch to Node again, at least. It’s a well-established environment, especially for Express applications.
In summary: Bun is still experimental. If you need something stable with reproducible memory performance, Node.js is the safer choice for now.