Commit 3ed3715
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 bce92de commit 3ed3715
2 files changed
Lines changed: 29 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
308 | 309 | | |
309 | 310 | | |
310 | 311 | | |
| |||
332 | 333 | | |
333 | 334 | | |
334 | 335 | | |
335 | | - | |
| 336 | + | |
336 | 337 | | |
337 | 338 | | |
338 | 339 | | |
| |||
486 | 487 | | |
487 | 488 | | |
488 | 489 | | |
489 | | - | |
| 490 | + | |
490 | 491 | | |
491 | 492 | | |
492 | 493 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
770 | 770 | | |
771 | 771 | | |
772 | 772 | | |
773 | | - | |
| 773 | + | |
774 | 774 | | |
775 | | - | |
| 775 | + | |
| 776 | + | |
776 | 777 | | |
777 | 778 | | |
778 | 779 | | |
| 780 | + | |
779 | 781 | | |
780 | | - | |
| 782 | + | |
781 | 783 | | |
782 | 784 | | |
783 | 785 | | |
| |||
795 | 797 | | |
796 | 798 | | |
797 | 799 | | |
798 | | - | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
799 | 803 | | |
800 | | - | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
801 | 807 | | |
802 | | - | |
| 808 | + | |
803 | 809 | | |
804 | 810 | | |
805 | 811 | | |
| |||
810 | 816 | | |
811 | 817 | | |
812 | 818 | | |
813 | | - | |
814 | | - | |
815 | | - | |
816 | | - | |
817 | | - | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
818 | 828 | | |
819 | 829 | | |
820 | 830 | | |
| |||
0 commit comments