apple / swift-nio-http2

HTTP/2 support for SwiftNIO
https://swiftpackageindex.com/apple/swift-nio-http2/main/documentation/niohttp2
Apache License 2.0
465 stars 82 forks source link

Make FramePayload.Data class-backed #365

Closed Lukasa closed 1 year ago

Lukasa commented 1 year ago

Motivation:

Using indirect cases makes unwrapping and rewrapping HTTP/2 frames more expensive than it needs to be. As FramePayload.Data is essentially always stuffed into a FramePayload enum, we may as well just class-back it and avoid the extra allocs.

Modifications:

Make FramePayload.Data class-backed

Result:

Fewer allocations in many use-cases

Lukasa commented 1 year ago

@swift-server-bot test perf please

swift-server-bot commented 1 year ago

performance report

build id: 22

timestamp: Thu Dec 8 16:28:46 UTC 2022

results

nameminmaxmeanstd
1_conn_10k_reqs 1.7025580406188965 1.7125840187072754 1.7083839058876038 0.0028372740176298094
encode_100k_header_blocks_indexable 0.14495205879211426 0.14557909965515137 0.14531049728393555 0.00020014907826462826
encode_100k_header_blocks_nonindexable 0.37740492820739746 0.38304901123046875 0.3787545084953308 0.002064278063940128
encode_100k_header_blocks_neverIndexed 0.3750419616699219 0.3778679370880127 0.3761909008026123 0.0008590421886194513
decode_100k_header_blocks_indexable 0.10044407844543457 0.10103702545166016 0.10073181390762329 0.00025617933052259577
decode_100k_header_blocks_nonindexable 0.12908005714416504 0.1296989917755127 0.12942420244216918 0.0002662392839354932
decode_100k_header_blocks_neverIndexed 0.12908601760864258 0.12964999675750732 0.12946549654006959 0.00020141080493322463
hpackheaders_canonical_form 0.04079699516296387 0.041329026222229004 0.04093151092529297 0.00021093071038531585
hpackheaders_canonical_form_trimming_whitespace 0.052275896072387695 0.053781986236572266 0.05265899896621704 0.0005560957406551174
hpackheaders_canonical_form_trimming_whitespace_short_strings 0.048516035079956055 0.04903304576873779 0.04863320589065552 0.0002097473020345267
hpackheaders_canonical_form_trimming_whitespace_long_strings 0.057337045669555664 0.057882070541381836 0.05748649835586548 0.0002164252015041217
hpackheaders_normalize_httpheaders_removing_10k_conn_headers 0.059898972511291504 0.06059896945953369 0.060175204277038576 0.000227635775545384
hpackheaders_normalize_httpheaders_keeping_10k_conn_headers 0.04131901264190674 0.04180502891540527 0.04147217273712158 0.00017121570256875657
huffman_encode_basic 1.0781909227371216 1.0791959762573242 1.078720796108246 0.00032709742830846225
huffman_encode_complex 0.6889619827270508 0.7188379764556885 0.6922917127609253 0.009330835302962765
huffman_decode_basic 0.08125507831573486 0.08173608779907227 0.08145709037780761 0.00019700701739577863
huffman_decode_complex 0.06547391414642334 0.06612396240234375 0.06561750173568726 0.00022463581416701472
server_only_10k_requests_1_concurrent 0.3872140645980835 0.3876849412918091 0.387465500831604 0.00014287226362451696
server_only_10k_requests_100_concurrent 0.31551599502563477 0.31653106212615967 0.3160356044769287 0.0003610304184552493
stream_teardown_10k_requests_100_concurrent 0.1577969789505005 0.15847206115722656 0.15819839239120484 0.00022750427278525487

comparison

name current previous winner diff
1_conn_10k_reqs 1.7083839058876038 1.7130406022071838 previous 0%
encode_100k_header_blocks_indexable 0.14531049728393555 0.1358804941177368 previous 7%
encode_100k_header_blocks_nonindexable 0.3787545084953308 0.3707668900489807 previous 2%
encode_100k_header_blocks_neverIndexed 0.3761909008026123 0.36662510633468626 previous 2%
decode_100k_header_blocks_indexable 0.10073181390762329 0.10299210548400879 current -1%
decode_100k_header_blocks_nonindexable 0.12942420244216918 0.1316897988319397 current -1%
decode_100k_header_blocks_neverIndexed 0.12946549654006959 0.13155900239944457 current -1%
hpackheaders_canonical_form 0.04093151092529297 0.044475996494293214 current -8%
hpackheaders_canonical_form_trimming_whitespace 0.05265899896621704 0.05536129474639893 current -5%
hpackheaders_canonical_form_trimming_whitespace_short_strings 0.04863320589065552 0.05179709196090698 current -5%
hpackheaders_canonical_form_trimming_whitespace_long_strings 0.05748649835586548 0.06033010482788086 current -4%
hpackheaders_normalize_httpheaders_removing_10k_conn_headers 0.060175204277038576 0.05963621139526367 previous 1%
hpackheaders_normalize_httpheaders_keeping_10k_conn_headers 0.04147217273712158 0.04127819538116455 previous 0%
huffman_encode_basic 1.078720796108246 1.0852394819259643 current 0%
huffman_encode_complex 0.6922917127609253 0.6959344029426575 current 0%
huffman_decode_basic 0.08145709037780761 0.08448160886764526 current -3%
huffman_decode_complex 0.06561750173568726 0.06701929569244384 current -2%
server_only_10k_requests_1_concurrent 0.387465500831604 0.3863301157951355 previous 0%
server_only_10k_requests_100_concurrent 0.3160356044769287 0.31253368854522706 previous 1%
stream_teardown_10k_requests_100_concurrent 0.15819839239120484 0.15987279415130615 current -1%

significant differences found