Skip to content

Conversation

ctz
Copy link
Member

@ctz ctz commented Jul 19, 2024

This PR starts with a repro case for #2040 , with the end goal of a) that and all other tests passing, and b) the deframer code being something I feel I can live with.

Copy link

rustls-benchmarking bot commented Jul 19, 2024

Benchmark results

Instruction counts

Significant differences

⚠️ There are significant instruction count differences

Click to expand
Scenario Baseline Candidate Diff Threshold
handshake_tickets_ring_1.2_rsa_aes_client 4515808 4550244 ⚠️ 34436 (0.76%) 0.20%
handshake_tickets_aws_lc_rs_1.2_rsa_aes_client 4320264 4351735 ⚠️ 31471 (0.73%) 0.20%
handshake_session_id_ring_1.2_rsa_aes_server 4239499 4269849 ⚠️ 30350 (0.72%) 0.20%
handshake_tickets_ring_1.2_rsa_aes_server 4677368 4707668 ⚠️ 30300 (0.65%) 0.20%
handshake_session_id_ring_1.2_rsa_aes_client 4251356 4278345 ⚠️ 26989 (0.63%) 0.20%
handshake_session_id_aws_lc_rs_1.2_rsa_aes_client 3994910 4018713 ⚠️ 23803 (0.60%) 0.20%
handshake_tickets_aws_lc_rs_1.3_rsa_aes_client 31132304 31203529 ⚠️ 71225 (0.23%) 0.20%
handshake_session_id_aws_lc_rs_1.3_rsa_chacha_client 30643292 30711749 ⚠️ 68457 (0.22%) 0.20%
handshake_tickets_aws_lc_rs_1.3_rsa_chacha_client 31113513 31182944 ⚠️ 69431 (0.22%) 0.20%
handshake_session_id_aws_lc_rs_1.3_rsa_aes_client 30669442 30737035 ⚠️ 67593 (0.22%) 0.20%
handshake_session_id_aws_lc_rs_1.3_ecdsap256_aes_client 30656959 30721980 ⚠️ 65021 (0.21%) 0.20%
handshake_tickets_aws_lc_rs_1.3_ecdsap256_aes_client 31116084 31180394 ⚠️ 64310 (0.21%) 0.20%
handshake_session_id_aws_lc_rs_1.3_ecdsap256_chacha_client 30630610 30693843 ⚠️ 63233 (0.21%) 0.20%
handshake_tickets_aws_lc_rs_1.3_ecdsap256_chacha_client 31095379 31158959 ⚠️ 63580 (0.20%) 0.20%

Other differences

Click to expand
Scenario Baseline Candidate Diff Threshold
handshake_tickets_aws_lc_rs_1.2_rsa_aes_server 4493037 4418346 -74691 (-1.66%) 4.45%
handshake_session_id_aws_lc_rs_1.2_rsa_aes_server 3943094 3902951 -40143 (-1.02%) 2.54%
handshake_no_resume_aws_lc_rs_1.2_rsa_aes_server 13377263 13436453 59190 (0.44%) 0.57%
handshake_session_id_aws_lc_rs_1.3_rsa_chacha_server 32874953 32975124 100171 (0.30%) 0.81%
handshake_no_resume_ring_1.3_ecdsap256_chacha_server 2135618 2140791 5173 (0.24%) 0.81%
handshake_tickets_aws_lc_rs_1.3_ecdsap384_chacha_client 31096975 31167100 70125 (0.23%) 0.27%
transfer_no_resume_aws_lc_rs_1.2_rsa_aes_server 46459981 46366669 -93312 (-0.20%) 0.53%
handshake_tickets_aws_lc_rs_1.3_ecdsap384_aes_client 31129783 31189555 59772 (0.19%) 0.29%
handshake_session_id_ring_1.3_ecdsap256_aes_client 41868914 41943959 75045 (0.18%) 0.20%
handshake_no_resume_ring_1.3_ecdsap256_chacha_client 3916077 3923014 6937 (0.18%) 0.31%
handshake_session_id_aws_lc_rs_1.3_ecdsap384_aes_client 30661549 30714904 53355 (0.17%) 0.41%
handshake_session_id_ring_1.3_ecdsap384_aes_client 41870170 41935291 65121 (0.16%) 0.20%
handshake_session_id_ring_1.3_ecdsap384_chacha_client 41789953 41854390 64437 (0.15%) 0.20%
handshake_tickets_ring_1.3_ecdsap384_aes_client 42318592 42383844 65252 (0.15%) 0.20%
handshake_no_resume_ring_1.3_ecdsap256_aes_server 2137995 2134699 -3296 (-0.15%) 0.85%
handshake_tickets_ring_1.3_rsa_aes_client 42336616 42401723 65107 (0.15%) 0.20%
handshake_session_id_aws_lc_rs_1.3_ecdsap384_chacha_client 30638885 30685839 46954 (0.15%) 0.45%
handshake_tickets_ring_1.3_ecdsap256_aes_client 42323563 42388292 64729 (0.15%) 0.20%
handshake_session_id_ring_1.3_rsa_aes_client 41889027 41953088 64061 (0.15%) 0.20%
handshake_tickets_ring_1.3_ecdsap384_chacha_client 42253504 42317500 63996 (0.15%) 0.20%
handshake_tickets_ring_1.3_rsa_chacha_client 42272018 42335123 63105 (0.15%) 0.20%
handshake_session_id_ring_1.3_rsa_chacha_client 41808445 41870802 62357 (0.15%) 0.20%
handshake_tickets_ring_1.3_ecdsap256_chacha_client 42259152 42317214 58062 (0.14%) 0.20%
handshake_session_id_ring_1.3_ecdsap256_chacha_client 41795882 41851481 55599 (0.13%) 0.20%
handshake_no_resume_aws_lc_rs_1.3_ecdsap384_aes_client 8858507 8869352 10845 (0.12%) 0.88%
transfer_no_resume_aws_lc_rs_1.3_rsa_aes_server 46442318 46495852 53534 (0.12%) 0.34%
handshake_tickets_aws_lc_rs_1.3_rsa_aes_server 33573989 33611363 37374 (0.11%) 0.72%
handshake_no_resume_aws_lc_rs_1.2_rsa_aes_client 2015250 2017157 1907 (0.09%) 0.20%
handshake_no_resume_aws_lc_rs_1.3_rsa_aes_client 2226049 2228130 2081 (0.09%) 0.20%
handshake_tickets_aws_lc_rs_1.3_ecdsap256_chacha_server 33517449 33548004 30555 (0.09%) 0.20%
handshake_tickets_aws_lc_rs_1.3_ecdsap384_aes_server 33550168 33580348 30180 (0.09%) 0.20%
handshake_tickets_aws_lc_rs_1.3_ecdsap256_aes_server 33550131 33580170 30039 (0.09%) 0.20%
handshake_tickets_aws_lc_rs_1.3_ecdsap384_chacha_server 33517700 33547509 29809 (0.09%) 0.20%
handshake_session_id_aws_lc_rs_1.3_ecdsap384_aes_server 32980407 33009731 29324 (0.09%) 0.20%
handshake_session_id_aws_lc_rs_1.3_ecdsap256_aes_server 32979493 33008806 29313 (0.09%) 0.20%
handshake_no_resume_aws_lc_rs_1.3_ecdsap384_chacha_client 8853374 8861147 7773 (0.09%) 1.35%
handshake_no_resume_aws_lc_rs_1.3_rsa_chacha_client 2233129 2235080 1951 (0.09%) 0.20%
handshake_session_id_aws_lc_rs_1.3_ecdsap256_chacha_server 32939526 32968200 28674 (0.09%) 0.20%
handshake_session_id_aws_lc_rs_1.3_ecdsap384_chacha_server 32939960 32967932 27972 (0.08%) 0.20%
handshake_session_id_ring_1.3_ecdsap256_aes_server 43439212 43473942 34730 (0.08%) 0.20%
handshake_no_resume_ring_1.3_rsa_chacha_client 2955300 2957462 2162 (0.07%) 0.20%
handshake_session_id_ring_1.3_ecdsap384_chacha_server 43341579 43372500 30921 (0.07%) 0.20%
handshake_tickets_ring_1.3_ecdsap384_chacha_server 43933286 43964252 30966 (0.07%) 0.20%
handshake_no_resume_ring_1.3_rsa_aes_client 2949372 2951443 2071 (0.07%) 0.20%
handshake_no_resume_aws_lc_rs_1.3_ecdsap256_aes_server 1915635 1916971 1336 (0.07%) 0.20%
handshake_session_id_ring_1.3_rsa_chacha_server 43339697 43369411 29714 (0.07%) 0.20%
handshake_tickets_ring_1.3_rsa_chacha_server 43931183 43960859 29676 (0.07%) 0.20%
transfer_no_resume_ring_1.3_ecdsap256_aes_client 58288872 58327664 38792 (0.07%) 0.20%
handshake_no_resume_ring_1.3_ecdsap256_aes_client 3919406 3916858 -2548 (-0.07%) 0.36%
transfer_no_resume_ring_1.2_rsa_aes_client 58172842 58210317 37475 (0.06%) 0.20%
transfer_no_resume_ring_1.3_ecdsap384_aes_client 58292685 58329737 37052 (0.06%) 0.20%
handshake_tickets_ring_1.3_rsa_aes_server 44013310 44040735 27425 (0.06%) 0.20%
transfer_no_resume_ring_1.3_rsa_aes_client 58297012 58333337 36325 (0.06%) 0.20%
handshake_no_resume_ring_1.2_rsa_aes_client 2852003 2853760 1757 (0.06%) 0.20%
handshake_session_id_ring_1.3_ecdsap384_aes_server 43443620 43470300 26680 (0.06%) 0.20%
transfer_no_resume_aws_lc_rs_1.3_ecdsap256_aes_client 58210844 58246203 35359 (0.06%) 0.20%
handshake_session_id_ring_1.3_rsa_aes_server 43440866 43467229 26363 (0.06%) 0.20%
handshake_tickets_ring_1.3_ecdsap384_aes_server 44016673 44043091 26418 (0.06%) 0.20%
transfer_no_resume_aws_lc_rs_1.3_rsa_aes_client 58214135 58248986 34851 (0.06%) 0.20%
handshake_no_resume_aws_lc_rs_1.3_rsa_chacha_server 13834616 13826426 -8190 (-0.06%) 1.12%
handshake_session_id_ring_1.3_ecdsap256_chacha_server 43343854 43369079 25225 (0.06%) 0.20%
handshake_tickets_ring_1.3_ecdsap256_aes_server 44017538 44043129 25591 (0.06%) 0.20%
handshake_tickets_ring_1.3_ecdsap256_chacha_server 43934330 43959562 25232 (0.06%) 0.20%
transfer_no_resume_aws_lc_rs_1.2_rsa_aes_client 68633183 68667406 34223 (0.05%) 0.20%
handshake_no_resume_aws_lc_rs_1.3_ecdsap256_chacha_server 1919121 1920027 906 (0.05%) 0.20%
transfer_no_resume_aws_lc_rs_1.3_ecdsap256_chacha_client 92667004 92706117 39113 (0.04%) 0.20%
handshake_no_resume_aws_lc_rs_1.3_ecdsap256_chacha_client 3384132 3385511 1379 (0.04%) 0.20%
transfer_no_resume_aws_lc_rs_1.3_rsa_chacha_server 80568957 80601748 32791 (0.04%) 0.25%
handshake_session_id_aws_lc_rs_1.3_rsa_aes_server 32950929 32964191 13262 (0.04%) 0.73%
transfer_no_resume_ring_1.3_ecdsap384_chacha_client 92625401 92661766 36365 (0.04%) 0.20%
transfer_no_resume_ring_1.3_rsa_chacha_client 92630134 92666211 36077 (0.04%) 0.20%
transfer_no_resume_aws_lc_rs_1.3_rsa_chacha_client 92671152 92707026 35874 (0.04%) 0.20%
transfer_no_resume_aws_lc_rs_1.3_ecdsap384_aes_client 58238878 58257443 18565 (0.03%) 0.21%
transfer_no_resume_aws_lc_rs_1.3_ecdsap384_chacha_client 92691167 92719517 28350 (0.03%) 0.20%
transfer_no_resume_ring_1.3_ecdsap256_chacha_client 92633417 92660234 26817 (0.03%) 0.20%
handshake_no_resume_aws_lc_rs_1.3_ecdsap384_chacha_server 4392723 4393884 1161 (0.03%) 0.20%
transfer_no_resume_ring_1.3_ecdsap256_aes_server 46446715 46458166 11451 (0.02%) 0.20%
handshake_tickets_aws_lc_rs_1.3_rsa_chacha_server 33468664 33476042 7378 (0.02%) 0.74%
handshake_no_resume_aws_lc_rs_1.3_ecdsap384_aes_server 4389547 4390421 874 (0.02%) 0.20%
handshake_no_resume_ring_1.2_rsa_aes_server 11989827 11992174 2347 (0.02%) 0.20%
transfer_no_resume_ring_1.2_rsa_aes_server 46368101 46375411 7310 (0.02%) 0.20%
transfer_no_resume_ring_1.3_rsa_aes_server 46462777 46469887 7110 (0.02%) 0.20%
transfer_no_resume_aws_lc_rs_1.3_ecdsap384_aes_server 46428845 46435774 6929 (0.01%) 0.20%
transfer_no_resume_ring_1.3_ecdsap384_aes_server 46454430 46461167 6737 (0.01%) 0.20%
transfer_no_resume_aws_lc_rs_1.3_ecdsap256_aes_server 46429319 46434556 5237 (0.01%) 0.20%
transfer_no_resume_ring_1.3_ecdsap384_chacha_server 80507328 80514673 7345 (0.01%) 0.20%
transfer_no_resume_aws_lc_rs_1.3_ecdsap384_chacha_server 80607895 80615209 7314 (0.01%) 0.20%
transfer_no_resume_ring_1.3_rsa_chacha_server 80515881 80522828 6947 (0.01%) 0.20%
handshake_no_resume_ring_1.3_ecdsap384_aes_server 13741793 13742924 1131 (0.01%) 0.20%
handshake_no_resume_ring_1.3_rsa_aes_server 12179271 12180217 946 (0.01%) 0.20%
transfer_no_resume_aws_lc_rs_1.3_ecdsap256_chacha_server 80607877 80614063 6186 (0.01%) 0.20%
handshake_no_resume_ring_1.3_rsa_chacha_server 12185514 12186373 859 (0.01%) 0.20%
handshake_no_resume_aws_lc_rs_1.3_ecdsap256_aes_client 3381436 3381223 -213 (-0.01%) 0.23%
handshake_no_resume_ring_1.3_ecdsap384_chacha_server 13744023 13744830 807 (0.01%) 0.20%
handshake_no_resume_ring_1.3_ecdsap384_chacha_client 35474089 35475912 1823 (0.01%) 0.20%
handshake_no_resume_ring_1.3_ecdsap384_aes_client 35472165 35473860 1695 (0.00%) 0.20%
handshake_no_resume_aws_lc_rs_1.3_rsa_aes_server 13777065 13777340 275 (0.00%) 0.99%
transfer_no_resume_ring_1.3_ecdsap256_chacha_server 80508389 80507022 -1367 (-0.00%) 0.20%

Wall-time

Significant differences

There are no significant wall-time differences

Other differences

Click to expand
Scenario Baseline Candidate Diff Threshold
handshake_no_resume_aws_lc_rs_1.2_rsa_aes 1.36 ms 1.39 ms 0.03 ms (1.85%) 6.74%
handshake_no_resume_aws_lc_rs_1.3_rsa_chacha 1.41 ms 1.43 ms 0.03 ms (1.84%) 6.34%
handshake_no_resume_aws_lc_rs_1.3_rsa_aes 1.42 ms 1.44 ms 0.02 ms (1.66%) 5.90%
handshake_session_id_aws_lc_rs_1.2_rsa_aes 2.07 ms 2.10 ms 0.03 ms (1.63%) 4.36%
handshake_tickets_aws_lc_rs_1.2_rsa_aes 2.24 ms 2.27 ms 0.03 ms (1.49%) 5.19%
handshake_no_resume_ring_1.2_rsa_aes 991.47 µs 978.82 µs -12.64 µs (-1.28%) 1.76%
transfer_no_resume_aws_lc_rs_1.3_ecdsap256_aes 4.53 ms 4.48 ms -0.06 ms (-1.27%) 4.87%
transfer_no_resume_aws_lc_rs_1.3_ecdsap384_aes 5.26 ms 5.20 ms -0.06 ms (-1.21%) 4.46%
transfer_no_resume_ring_1.2_rsa_aes 6.77 ms 6.70 ms -0.07 ms (-1.10%) 2.97%
handshake_no_resume_aws_lc_rs_1.3_ecdsap256_aes 484.74 µs 480.47 µs -4.27 µs (-0.88%) 3.28%
handshake_no_resume_aws_lc_rs_1.3_ecdsap256_chacha 483.78 µs 479.57 µs -4.21 µs (-0.87%) 3.42%
transfer_no_resume_ring_1.3_rsa_aes 6.85 ms 6.79 ms -0.06 ms (-0.85%) 2.34%
transfer_no_resume_ring_1.3_ecdsap256_aes 6.36 ms 6.31 ms -0.05 ms (-0.84%) 2.66%
transfer_no_resume_aws_lc_rs_1.3_rsa_aes 5.48 ms 5.44 ms -0.03 ms (-0.62%) 4.00%
transfer_no_resume_ring_1.3_ecdsap384_aes 9.46 ms 9.40 ms -0.06 ms (-0.60%) 1.92%
handshake_session_id_ring_1.3_ecdsap256_aes 6.77 ms 6.81 ms 0.04 ms (0.60%) 1.00%
transfer_no_resume_aws_lc_rs_1.2_rsa_aes 5.46 ms 5.43 ms -0.03 ms (-0.56%) 3.67%
handshake_no_resume_ring_1.3_ecdsap256_chacha 508.30 µs 505.58 µs -2.72 µs (-0.54%) 2.95%
handshake_session_id_ring_1.3_rsa_aes 7.25 ms 7.29 ms 0.04 ms (0.52%) 1.00%
transfer_no_resume_ring_1.3_ecdsap256_chacha 13.00 ms 12.94 ms -0.06 ms (-0.48%) 1.26%
handshake_session_id_aws_lc_rs_1.3_rsa_chacha 6.33 ms 6.36 ms 0.03 ms (0.45%) 1.00%
handshake_session_id_ring_1.3_ecdsap256_chacha 6.73 ms 6.77 ms 0.03 ms (0.45%) 1.00%
handshake_tickets_ring_1.3_ecdsap256_chacha 6.78 ms 6.81 ms 0.03 ms (0.45%) 1.00%
handshake_session_id_ring_1.3_ecdsap384_aes 9.85 ms 9.89 ms 0.04 ms (0.43%) 1.00%
handshake_no_resume_ring_1.3_ecdsap256_aes 511.05 µs 508.89 µs -2.17 µs (-0.42%) 2.72%
transfer_no_resume_ring_1.3_rsa_chacha 13.49 ms 13.43 ms -0.06 ms (-0.42%) 1.00%
handshake_session_id_aws_lc_rs_1.3_rsa_aes 6.35 ms 6.38 ms 0.03 ms (0.42%) 1.40%
transfer_no_resume_ring_1.3_ecdsap384_chacha 16.10 ms 16.04 ms -0.07 ms (-0.41%) 1.26%
handshake_tickets_ring_1.3_ecdsap256_aes 6.83 ms 6.85 ms 0.03 ms (0.41%) 1.00%
handshake_tickets_ring_1.3_rsa_chacha 7.25 ms 7.28 ms 0.03 ms (0.39%) 1.00%
transfer_no_resume_aws_lc_rs_1.3_ecdsap256_chacha 12.99 ms 12.94 ms -0.05 ms (-0.38%) 1.50%
handshake_tickets_aws_lc_rs_1.3_rsa_chacha 6.41 ms 6.43 ms 0.02 ms (0.37%) 1.00%
handshake_session_id_ring_1.3_rsa_chacha 7.22 ms 7.24 ms 0.03 ms (0.37%) 1.00%
handshake_tickets_ring_1.3_rsa_aes 7.30 ms 7.33 ms 0.03 ms (0.36%) 1.00%
transfer_no_resume_aws_lc_rs_1.3_ecdsap384_chacha 13.72 ms 13.67 ms -0.05 ms (-0.36%) 1.21%
handshake_session_id_ring_1.3_ecdsap384_chacha 9.82 ms 9.85 ms 0.03 ms (0.35%) 1.00%
handshake_session_id_ring_1.2_rsa_aes 1.57 ms 1.58 ms 0.01 ms (0.32%) 2.37%
handshake_tickets_ring_1.3_ecdsap384_chacha 9.86 ms 9.89 ms 0.03 ms (0.30%) 1.00%
handshake_tickets_aws_lc_rs_1.3_rsa_aes 6.41 ms 6.42 ms 0.02 ms (0.29%) 1.08%
handshake_tickets_ring_1.3_ecdsap384_aes 9.90 ms 9.93 ms 0.03 ms (0.27%) 1.00%
handshake_no_resume_ring_1.3_rsa_chacha 993.89 µs 991.75 µs -2.14 µs (-0.22%) 1.00%
handshake_no_resume_ring_1.3_rsa_aes 992.81 µs 990.80 µs -2.01 µs (-0.20%) 1.09%
transfer_no_resume_aws_lc_rs_1.3_rsa_chacha 13.94 ms 13.91 ms -0.03 ms (-0.20%) 1.81%
handshake_no_resume_aws_lc_rs_1.3_ecdsap384_chacha 1.20 ms 1.20 ms -0.00 ms (-0.19%) 1.12%
handshake_tickets_aws_lc_rs_1.3_ecdsap256_chacha 5.46 ms 5.45 ms -0.01 ms (-0.17%) 1.38%
handshake_tickets_aws_lc_rs_1.3_ecdsap384_aes 6.17 ms 6.16 ms -0.01 ms (-0.16%) 1.42%
handshake_session_id_aws_lc_rs_1.3_ecdsap384_chacha 6.11 ms 6.10 ms -0.01 ms (-0.16%) 1.44%
handshake_no_resume_aws_lc_rs_1.3_ecdsap384_aes 1.20 ms 1.20 ms -0.00 ms (-0.15%) 1.27%
handshake_tickets_aws_lc_rs_1.3_ecdsap256_aes 5.45 ms 5.45 ms -0.01 ms (-0.12%) 1.34%
handshake_session_id_aws_lc_rs_1.3_ecdsap256_chacha 5.39 ms 5.38 ms -0.01 ms (-0.11%) 1.28%
handshake_session_id_aws_lc_rs_1.3_ecdsap384_aes 6.12 ms 6.11 ms -0.01 ms (-0.11%) 1.20%
handshake_tickets_aws_lc_rs_1.3_ecdsap384_chacha 6.17 ms 6.17 ms -0.01 ms (-0.11%) 1.57%
handshake_tickets_ring_1.2_rsa_aes 1.66 ms 1.66 ms -0.00 ms (-0.09%) 2.36%
handshake_no_resume_ring_1.3_ecdsap384_aes 3.60 ms 3.60 ms -0.00 ms (-0.09%) 1.00%
handshake_no_resume_ring_1.3_ecdsap384_chacha 3.60 ms 3.60 ms -0.00 ms (-0.09%) 1.00%
handshake_session_id_aws_lc_rs_1.3_ecdsap256_aes 5.40 ms 5.40 ms -0.00 ms (-0.02%) 1.27%

Additional information

Historical results

Checkout details:

@ctz ctz force-pushed the jbp-deframer-rewrite branch from 957f46a to 984a459 Compare July 19, 2024 17:15
Copy link

codecov bot commented Jul 19, 2024

Codecov Report

Attention: Patch coverage is 99.46019% with 4 lines in your changes missing coverage. Please review.

Project coverage is 94.35%. Comparing base (3242cc9) to head (af08336).
Report is 20 commits behind head on main.

Files Patch % Lines
rustls/src/msgs/deframer/buffers.rs 98.61% 2 Missing ⚠️
rustls/src/conn.rs 99.38% 1 Missing ⚠️
rustls/src/conn/unbuffered.rs 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2049      +/-   ##
==========================================
+ Coverage   94.29%   94.35%   +0.05%     
==========================================
  Files          97       99       +2     
  Lines       21913    21879      -34     
==========================================
- Hits        20663    20644      -19     
+ Misses       1250     1235      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a really nice direction. I know from trying to untangle parts of this code before that it's very non-trivial to navigate the complexity of the task and the requirements imposed by the borrow checker. Kudos for managing 🙇 It was a really interesting exercise to read through this.

Here's an initial pass with some feedback. IMO this feels like a case where individual commits help for review, but it might be better to land as a one-and-done squashed commit. Either that or once it's further along it might be sensible to revisit the intermediate commits to make sure they build/test/lint cleanly.

@ctz ctz force-pushed the jbp-deframer-rewrite branch 5 times, most recently from c4e3b0b to 9d05d70 Compare July 23, 2024 10:29
@ctz ctz marked this pull request as ready for review July 23, 2024 10:29
@ctz
Copy link
Member Author

ctz commented Jul 23, 2024

I think this is ready to go from my side.

Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's some initial feedback. So far I have not done an in-depth review yet -- after starting to look at types called Locator and Delocator I was a bit scared so I first want to ask some questions:

  • What is the conceptual problem that this refactoring is solving? Presumably you're now close enough that you can articulate it in writing. Would be good to have some high-level design comments on what the important constraints here are and why this is the/an optional solution.
  • It looks like this is a rewrite from scratch, and it shows in the commit history, which makes it harder to review.

I guess as a main contributor of the previous deframer (though before it got further complexified in order to support the unbuffered case) I'm still trying to grasp the (design/concept) issues here and how this makes rustls (and our lives as maintainers) better.

Also, the commit history clearly shows this started as a from-scratch rewrite. It would be a lot easier to review this against the existing implementation if the commit history was closer to replacing it in the smallest pieces possible (though I understand this might be hard/labor-intensive).

}
}

impl<'a, 'b> Iterator for DeframerIter<'a, 'b> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is similar as the point that @cpu made before, but (perhaps more concretely) this would be easier to review if it was introduced in the same commit that removed the original version of this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about merging together the commit that deletes the old deframer code, the commit that introduces the iterator-based one, and the commit that moves calling code between them. That will be a big commit, but it might be an improvement on the current state?

I would suggest keeping the new handshake deframer introduction in its own commit (before the big one) because it functionally is quite dissimilar to the old code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ Have done this.

@ctz ctz force-pushed the jbp-deframer-rewrite branch 2 times, most recently from d372cba to 226f582 Compare July 24, 2024 06:47
@ctz
Copy link
Member Author

ctz commented Jul 24, 2024

  • What is the conceptual problem that this refactoring is solving? Presumably you're now close enough that you can articulate it in writing. Would be good to have some high-level design comments on what the important constraints here are and why this is the/an optional solution.

I think for me the previous deframer was something I could hold my nose at while it worked, but then inscrutable once I had to debug an issue in it. I think the root of that was one piece of code with too many responsibilities. It was a reasonable process how it got there -- having it decrypt the messages and join together the handshake stream was done to achieve very real performance improvements, but it became no longer necessary once the inbound message types started borrowing their data.

But, to be more concrete about the actual issue that got me to giving up on the existing deframer: basically DeframerSliceBuffer::take was incorrect in a ~unfixable way. It had to move the buffer (via the mem::take/split_at_mut trick) to obtain a return value of the correct lifetime, but then had no reasonable way to adjust for that in indices into the buffer that came from outside the DeframerSliceBuffer. This happened to work in the buffered API, because DeframerSliceBuffer::take was the very last call on any given DeframerSliceBuffer object. But I'm quite surprised the unbuffered API worked as well as it did, because even a cursory exercise of the DeframerSliceBuffer API after take() is called shows the fundamental issue:

    #[test]
    fn take_panics() {
        let mut buf = [1, 2, 3];
        let mut dsb = DeframerSliceBuffer::new(&mut buf);
        let rs = RawSlice::from(&dsb.filled()[..1]);

        assert_eq!(&[1], dsb.take(rs));

        // any of the following lines panic (not just because the assert fails)
        assert_eq!(&[2, 3], dsb.filled());
        assert_eq!(2, dsb.len());
        assert!(!dsb.is_empty());
    }

To reframe that in terms of a conceptual problem, I'd say it is symptomatic of not being precise about what code requires mutable access to the input buffer (and the complexity which came with achieving that). The main reduction in complexity in this PR is achieved in minimising and containing those areas.

The other structural issue I didn't like with the existing code was how much complexity budget was applied to having the deframer be involved with writing messages into the underlying buffer for received quic handshake messages. I think the situation at the end of this PR in that area is an improvement.

Having spent quite a bit of time on this area of the code so far, I also have some future improvements in mind:

  • at the moment we have (at least) two places where errors can be fused -- probably we can remove the one in the deframer, at which point we'll be left with just DeframerIter that requires no context, and the connection-level fused error in the Err variant of state.
  • I think it would be ideal if we can make code that handles a single message (eg, process_main_protocol) instead work on an iterator of such messages, which should mean we can realise the benefits of trait State impls that only borrow their input (at the moment, this doesn't happen because into_owned is called unconditionally on these for every state transition.)

@ctz
Copy link
Member Author

ctz commented Jul 24, 2024

  • at the moment we have (at least) two places where errors can be fused -- probably we can remove the one in the deframer, at which point we'll be left with just DeframerIter that requires no context, and the connection-level fused error in the Err variant of state.

Have thought about it a bit more, and I'm going to do this in this PR.

@ctz ctz force-pushed the jbp-deframer-rewrite branch 2 times, most recently from a5c319d to 72ba041 Compare July 25, 2024 13:45
ctz added 4 commits July 25, 2024 15:58
Test data extracted from run of unbuffered-client
against icanhazip.com
Put it inside the crate and build it unconditionally so
breakage is visible without needing to run `cargo fuzz build`.

Eliminate the exports under `internals` that exist solely
for it.
@ctz ctz force-pushed the jbp-deframer-rewrite branch from 72ba041 to 2ab347e Compare July 25, 2024 14:58
Copy link

@samlh samlh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the drive-by review!

I was reading this PR out of curiosity, and found it remarkably readable, but I got nerd-sniped and had a couple of shower thoughts on how it could potentially be improved.

Please do disregard this if the comments aren't helpful!

// if this is the last handshake message, then we'll end
// up with an empty `spans` and can discard the remainder
// of the input buffer.
let discard = if self.deframer.spans.len() - 1 == self.index {

This comment was marked as resolved.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is actually pretty crucial that no "discard" operation happens while there is any partial or full message, as it moves the buffer and therefore invalidates our ideas about where the message fragment is.

// `_last_incomplete`, and reparse the result.
//
// we cannot merge these processes, because `coalesce` mutates the underlying
// buffer, and `msg` borrows it.
Copy link

@samlh samlh Jul 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reading this, I wonder if it would make sense for input_message to take msg: InboundUnborrowedMessage and containing_buffer: &mut [u8] instead.

This would allow hiding the coalesce logic inside the handshake deframer instead of exposing it to the callers.

It would require the caller to use .unborrow(), which is ugly, but I think the coalesce() calls are also ugly - it's a case of "pick your poison".

Doing so would simplify the internal invariants - for example:

  • requires_coalesce would only need to look at self.spans.last() as all previous spans would be guaranteed to be coalesced.

I understand that this split between input_message and coalesce is one of the major design points of this PR, however, so please feel free to ignore this comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I view InboundUnborrowedMessage as a bit of a hack as part of convincing the borrow checker to determine the correct lifetime relationship between the buffer and object returned by deframe(). So while this would work equally well, perhaps better, I'm minded to keep it as is.

@ctz ctz force-pushed the jbp-deframer-rewrite branch from 2ab347e to 8aa2b71 Compare July 29, 2024 16:09
ctz added 5 commits July 29, 2024 17:25
`MessageDeframer` is replaced with a combination of the new `deframer::DeframerIter`,
`deframer::handshake::HandshakeDeframer` and the existing `RecordLayer`.

QUIC code directly inputs data to `HandshakeDeframer`.  There is no
QUIC-specific code now in either deframer.

Some policy code has been hoisted up into `ConnectionCore`.

The old `MessageDeframer` is eliminated, as is code which became unused
after that.
@ctz ctz force-pushed the jbp-deframer-rewrite branch from 8aa2b71 to af08336 Compare July 29, 2024 16:33
@ctz ctz requested a review from cpu July 30, 2024 16:29
/// |
/// spans = [ { bounds = (5, 18), size = Some(9), .. } ]
/// ```
pub(crate) fn coalesce(&mut self, containing_buffer: &mut [u8]) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The addition of the comment with the diagram of buffer contents is really nice, exactly what I was hoping to see. Thank you!

@ctz
Copy link
Member Author

ctz commented Jul 31, 2024

Going to merge this with one review, but as always happy to address later comments in a follow-up PR.

@ctz ctz added this pull request to the merge queue Jul 31, 2024
Merged via the queue into main with commit 1177a46 Jul 31, 2024
46 checks passed
@ctz ctz deleted the jbp-deframer-rewrite branch July 31, 2024 10:28
@stevefan1999-personal
Copy link
Contributor

assertion `left == right` failed
  left: InvalidCertificate(Expired)
 right: InvalidCertificate(UnknownIssuer)
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    tests_with_aws_lc_rs::tests::tls13_packed_handshake

Seems like the captured data is expired

@ctz
Copy link
Member Author

ctz commented Oct 1, 2024

Thanks for the ping -- will address this shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants