{{ message }}
Commit 157bd07
http2: reduce per-request allocations
Cut several sources of per-stream/per-request overhead on the hot
path:
- Track 'priority'/'frameError' stream listeners by overriding the
EventEmitter methods on Http2Stream instead of subscribing to
'newListener'/'removeListener', which made every listener add and
remove on every stream emit an extra tracking event.
- Replace the per-call SafeSet and sensitive-header mapping in
buildNgHeaderString with a lazily allocated array and an
empty-array fast path, and skip the HTTP token regex and
connection-specific header checks for well-known single-value
header names.
- Replace per-call closures with shared named handlers in
onStreamClose, afterShutdown and Http2Stream._destroy.
- Skip the pendingStreams Set add/delete for streams that are
created with their native handle already available (all server
streams).
- Hoist the per-request onStreamTimeout closure factories in the
compat layer to module-level handlers, and avoid a once() wrapper
allocation per server stream.
h2load, 1 KiB response payload, -c 4 -m 100, mean of 6 alternating
runs: core API 60.2k -> 69.3k req/s (+15%), compat API 43.6k ->
46.2k req/s (+5.9%).
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: #64265
Backport-PR-URL: #64663
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>1 parent 3833fce commit 157bd07
2 files changed
Lines changed: 29 additions & 18 deletions

0 commit comments