5 comments

[ 3.8 ms ] story [ 20.7 ms ] thread
I have been troubled by bun’s prior benchmarks for WebSockets. Node does not have a native WebSocket library so bun compares a popular Node package, ws, against itself. That’s fair and practical but problematic from two technical perspectives.

1) bun is stress testing message send, not message receive. I find that using a better optimized implementation on Node it takes Node about 9x longer to receive a message than to send it and that difference compounds with increase of message frequency. On my laptop with DDR4 2133mhz memory I can send at up to 450,000 messages per second on Node (as opposed to bun’s 700,000 messages per second) before hitting garbage collection problems but receiving is dramatically slower. I suspect bun will be dramatically faster than Node on message receive frequency but I would still like to see the numbers.

2) common Node implementations of WebSockets execute messaging as streams over an established HTTP socket. This is certainly not a bun problem but it does make for a poor comparison. WebSockets are dramatically faster when executed over sockets from Node’s Net/TLS libraries directly as HTTP is not need at any step (even though the greeting packet looks like HTTP).