saplingjs / sapling

🌿 Sapling is a Node.js framework for faster-than-light web development.
https://www.saplingjs.com
MIT License
14 stars 0 forks source link

Investigate Bun #522

Closed groenroos closed 2 years ago

groenroos commented 2 years ago

Bun is a JS runtime that claims to be a (near?) drop-in replacement for Node, but with faster performance.

Investigate the extent of the performance benefit to this project. If it is as fast as they claim, find out what, if anything, must be done to support it.

groenroos commented 2 years ago

Seems like at least superficially, bun run index.js works seamlessly as a drop-in replacement for Node.js, as-is.

However, while Bun may have a 100ms speed advantage on spinning up the client, the difference in response performance according to wrk seems to be equivalent within margin of error / slightly worse;

node index

Running 30s test @ http://127.0.0.1:4000
  12 threads and 400 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   116.77ms   15.91ms 276.52ms   91.44%
    Req/Sec   174.41     82.85   333.00     66.75%
  61820 requests in 30.09s, 673.05MB read
  Socket errors: connect 155, read 220, write 0, timeout 0
Requests/sec:   2054.44
Transfer/sec:     22.37MB

Running 30s test @ http://127.0.0.1:4000/data/updates
  12 threads and 200 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   159.77ms   21.25ms 374.55ms   92.27%
    Req/Sec   110.67     44.26   161.00     53.68%
  36033 requests in 30.10s, 345.10MB read
  Socket errors: connect 0, read 81, write 0, timeout 0
Requests/sec:   1197.02
Transfer/sec:     11.46MB

bun run index.js

Running 30s test @ http://127.0.0.1:3000
  12 threads and 400 connectiit ons
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   122.75ms   21.82ms 360.02ms   92.76%
    Req/Sec   165.20     80.58   333.00     72.30%
  58789 requests in 30.10s, 640.61MB read
  Socket errors: connect 155, read 101, write 0, timeout 0
Requests/sec:   1953.20
Transfer/sec:     21.28MB

Running 30s test @ http://127.0.0.1:3000/data/updates
  12 threads and 200 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   165.74ms   21.95ms 357.85ms   92.46%
    Req/Sec   105.26     46.23   161.00     56.71%
  34720 requests in 30.10s, 332.23MB read
  Socket errors: connect 0, read 84, write 0, timeout 0
Requests/sec:   1153.45
Transfer/sec:     11.04MB

I tried to create a bundle to see if it improved things any, but the bun bun app.js command just seemed to hang indefinitely.

In conclusion, seems like no work is needed to support Bun for users who wish to use it, but there doesn't seem to be any immediately obvious low-hanging performance advantage for us here.

Closing the issue for now - but open to reopening if there is new info in the future.