Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(node): improve body streaming #26

Merged
merged 2 commits into from
Jan 15, 2025
Merged

Conversation

alexfriesen
Copy link
Contributor

This PR improves the streamBody functions performance and closes the stream after it's completed.

This change is strongly inspired by @honojs/node-server approach.

Before:

Node.js:         v22.13.0
OS:              darwin arm64
OHA:             1.6.0


node... 116485 req/sec
srvx... 62466 req/sec
srvx-fast... 101216 req/sec
┌───────────┬──────────────────┐
│ (index)   │ Values           │
├───────────┼──────────────────┤
│ node      │ '116485 req/sec' │
│ srvx-fast │ '101216 req/sec' │
│ srvx      │ '62466 req/sec'  │
└───────────┴──────────────────┘

After:

Node.js:         v22.13.0
OS:              darwin arm64
OHA:             1.6.0


node... 115214 req/sec
srvx... 66832 req/sec
srvx-fast... 101813 req/sec
┌───────────┬──────────────────┐
│ (index)   │ Values           │
├───────────┼──────────────────┤
│ node      │ '115214 req/sec' │
│ srvx-fast │ '101813 req/sec' │
│ srvx      │ '66832 req/sec'  │
└───────────┴──────────────────┘

@pi0
Copy link
Member

pi0 commented Jan 15, 2025

Thank you for PR ❤️ I did run bench on a few servers, and it seems the difference is not reliable (especially on -fast variant, the simple loop is sometimes faster in order of 10,000 )

However, I like the new impl because the socket is closed and we respect drain events 👍🏼

@pi0 pi0 changed the title perf: streamBody refactor(node): improve body streaming Jan 15, 2025
@pi0 pi0 merged commit 35277be into unjs:main Jan 15, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants