Commit bedf22f
committed
http2: skip trailers round trip for compat responses
The compat layer always responded with waitForTrailers set, so every
response paid for a wantTrailers C++ -> JS callback, an empty
sendTrailers() submission scheduled through setImmediate(), and an
extra empty DATA frame on the wire, even though the vast majority of
responses never register any trailers.
When the headers are flushed as part of response.end() and no
trailers have been registered, there is no further opportunity to
add trailers, so waitForTrailers can be skipped altogether. Headers
flushed early (writeHead, write, flushHeaders) keep the previous
behavior so trailers can still be added while streaming.
Trailers added after response.end() are now silently dropped,
matching the HTTP/1 response.addTrailers() semantics.
Also reuse a shared options object for Http2ServerRequest instances
created without explicit options.
h2load, 1 KiB response payload, -c 4 -m 100, mean of 6 alternating
runs: compat API 43.1k -> 49.9k req/s (+15.7% cumulative vs main).
Signed-off-by: Matteo Collina <hello@matteocollina.com>1 parent 331609b commit bedf22f
2 files changed
Lines changed: 24 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4410 | 4410 | | |
4411 | 4411 | | |
4412 | 4412 | | |
| 4413 | + | |
| 4414 | + | |
| 4415 | + | |
4413 | 4416 | | |
4414 | 4417 | | |
4415 | 4418 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
303 | 307 | | |
304 | 308 | | |
305 | 309 | | |
| |||
310 | 314 | | |
311 | 315 | | |
312 | 316 | | |
313 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
314 | 320 | | |
315 | 321 | | |
316 | 322 | | |
| |||
473 | 479 | | |
474 | 480 | | |
475 | 481 | | |
| 482 | + | |
| 483 | + | |
476 | 484 | | |
477 | 485 | | |
478 | 486 | | |
| |||
584 | 592 | | |
585 | 593 | | |
586 | 594 | | |
| 595 | + | |
587 | 596 | | |
588 | 597 | | |
589 | 598 | | |
| |||
839 | 848 | | |
840 | 849 | | |
841 | 850 | | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
842 | 857 | | |
843 | 858 | | |
844 | 859 | | |
| |||
898 | 913 | | |
899 | 914 | | |
900 | 915 | | |
901 | | - | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
902 | 921 | | |
903 | 922 | | |
904 | 923 | | |
| |||
0 commit comments