stream: skip unobserved 'readable' emission at EOF · nodejs/node@3882929 · GitHub
Skip to content

Commit 3882929

Browse files
mcollinaaduh95
authored andcommitted
stream: skip unobserved 'readable' emission at EOF
When a stream reaches its end via push(null) while nobody is observing it (no 'readable' listener, not flowing, no pending readable need), do not schedule the deferred 'readable' emission: it fires into the void and costs a tick. Record that the end-of-stream notification is owed instead; attaching a 'readable' listener later emits it, and read() and resume() reach the end of the stream on their own. As a side effect, a 'readable' listener attached more than a tick after an unobserved end now receives the owed 'readable' before 'end', where it previously received only 'end'. For an HTTP server this removes one nextTick and one dead emit per request whose body the handler never reads. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #65749 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 96d4c23 commit 3882929

2 files changed

Lines changed: 99 additions & 4 deletions

File tree

‎lib/internal/streams/readable.js‎

Lines changed: 23 additions & 4 deletions
Lines changed: 76 additions & 0 deletions

0 commit comments

Comments
 (0)