Home / Companies / Trigger.dev / Blog / Post Details
Content Deep Dive

Why we replaced Node.js with Bun for 5x throughput

Blog post from Trigger.dev

Post Details
Company
Date Published
Author
Nick undefined
Word Count
2,931
Language
English
Hacker News Points
-
Summary

In an effort to optimize performance, a company replaced Node.js with Bun in their Firestarter service, a latency-sensitive connection broker, resulting in a 5x increase in throughput. The transition involved several phases, including removing SQLite in favor of a composite-key Map for faster data matching, switching to Bun for its efficient HTTP handling, profiling to streamline hot path operations, and compiling Bun to a single binary to reduce image size and improve latency. Despite the improvements, a memory leak was identified due to unresolved Promise<Response> in the event of client disconnections, which was fixed by ensuring all promises settled properly. The changes led to significant reductions in CPU usage and memory consumption, enhancing the service's stability and performance in production environments. Additionally, the company shared insights on debugging Bun, emphasizing the importance of profiling and benchmarking at each stage to identify impactful optimizations.