Skip to content

Add inlinability to ByteBuffer getters. #1220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2019

Conversation

Lukasa
Copy link
Contributor

@Lukasa Lukasa commented Nov 4, 2019

Motivation:

In complex ByteBuffer parsing code a surprising amount of cost comes
from retain/release operations that are emitted by the compiler around
calls to readerIndex/writerIndex, readableBytes/writableBytes, and
ByteBufferSlice._lowerBound. These are all straightforward computed
properties based on usableFromInline operations, and so they can be made
inlinable.

Modifications:

Joannis' sample benchmark runtime is halved by eliminating
retains/releases.

Result:

Better, faster parsing code.

Motivation:

In complex ByteBuffer parsing code a surprising amount of cost comes
from retain/release operations that are emitted by the compiler around
calls to readerIndex/writerIndex, readableBytes/writableBytes, and
ByteBufferSlice._lowerBound. These are all straightforward computed
properties based on usableFromInline operations, and so they can be made
inlinable.

Modifications:

Joannis' sample benchmark runtime is halved by eliminating
retains/releases.

Result:

Better, faster parsing code.
@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Nov 4, 2019
@Lukasa Lukasa added this to the 2.10.0 milestone Nov 4, 2019
@Lukasa Lukasa requested review from weissi and glbrntt November 4, 2019 11:05
@Lukasa
Copy link
Contributor Author

Lukasa commented Nov 4, 2019

@swift-nio-bot test perf please

@swift-server-bot
Copy link

performance report

build id: 27

timestamp: Mon Nov 4 11:08:49 UTC 2019

results

nameminmaxmeanstd
write_http_headers 0.004823923110961914 0.005010008811950684 0.004857897758483887 5.478133453381008e-05
bytebuffer_write_12MB_short_string_literals 0.593250036239624 0.6011120080947876 0.5948729991912842 0.002292344025179719
bytebuffer_write_12MB_short_calculated_strings 0.5936750173568726 0.6166199445724487 0.5970544934272766 0.007175259575884407
bytebuffer_write_12MB_medium_string_literals 0.21548795700073242 0.2176910638809204 0.21646541357040405 0.000650023170281712
bytebuffer_write_12MB_medium_calculated_strings 0.23398900032043457 0.23646390438079834 0.23506758213043213 0.001000607430608878
bytebuffer_write_12MB_large_calculated_strings 0.21247994899749756 0.2151869535446167 0.2130693793296814 0.000814898096460794
bytebuffer_lots_of_rw 0.5331449508666992 0.5345180034637451 0.5337634801864624 0.00056721491220166
bytebuffer_write_http_response_ascii_only_as_string 0.044487953186035156 0.04525196552276611 0.044824302196502686 0.0002700534680030974
bytebuffer_write_http_response_ascii_only_as_staticstring 0.03528296947479248 0.03585803508758545 0.035434603691101074 0.00021859783321776796
bytebuffer_write_http_response_some_nonascii_as_string 0.04513990879058838 0.046090006828308105 0.04540679454803467 0.0003195918906131321
bytebuffer_write_http_response_some_nonascii_as_staticstring 0.03553903102874756 0.03639400005340576 0.035762906074523926 0.00029152241176600763
no-net_http1_10k_reqs_1_conn 0.1488199234008789 0.15006005764007568 0.1495995044708252 0.0003998071413884047
http1_10k_reqs_1_conn 0.6479489803314209 0.6523829698562622 0.6496414065361023 0.0015936202718398042
http1_10k_reqs_100_conns 0.6484209299087524 0.6534820795059204 0.6508766889572144 0.001712073176583364
future_whenallsucceed_100k_immediately_succeeded_off_loop 0.12315797805786133 0.12517094612121582 0.12425729036331176 0.0006461831147786549
future_whenallsucceed_100k_immediately_succeeded_on_loop 0.1242600679397583 0.1364060640335083 0.12621169090270995 0.0036415718393815674
future_whenallsucceed_100k_deferred_off_loop 0.6231130361557007 0.6299639940261841 0.6254552960395813 0.0020515094586737574
future_whenallsucceed_100k_deferred_on_loop 0.1943579912185669 0.20235097408294678 0.19647581577301027 0.002275390989482631
future_whenallcomplete_100k_immediately_succeeded_off_loop 0.10273396968841553 0.1053628921508789 0.10426560640335084 0.0006943858585722204
future_whenallcomplete_100k_immediately_succeeded_on_loop 0.10270798206329346 0.10409700870513916 0.10361130237579345 0.00043015944269388215
future_whenallcomplete_100k_deferred_off_loop 0.604451060295105 0.6147040128707886 0.6099182844161988 0.0030094668968328733
future_whenallcomplete_100k_deferred_on_loop 0.17949092388153076 0.18549597263336182 0.1811111807823181 0.001713956874759119
future_reduce_10k_futures 0.050312042236328125 0.05083596706390381 0.05056699514389038 0.00018770199118511028
future_reduce_into_10k_futures 0.05051600933074951 0.051467061042785645 0.05084251165390015 0.0002751685964094593
channel_pipeline_1m_events 0.21959197521209717 0.21979296207427979 0.21969289779663087 7.265697701753029e-05
websocket_encode_50b_space_at_front_1m_frames_cow 1.0178290605545044 1.0187819004058838 1.018279993534088 0.00026650111751963415
websocket_encode_1kb_space_at_front_100k_frames_cow 0.10412001609802246 0.10458099842071533 0.10436229705810547 0.00020445008464805816
websocket_encode_50b_no_space_at_front_1m_frames_cow 1.0156580209732056 1.0162339210510254 1.0158753991127014 0.00018448422533705184
websocket_encode_1kb_no_space_at_front_100k_frames_cow 0.10389697551727295 0.10446405410766602 0.10417648553848266 0.0002258312942248443
websocket_encode_50b_space_at_front_10k_frames 0.16859495639801025 0.1691889762878418 0.16899328231811522 0.00021424731973347747
websocket_encode_1kb_space_at_front_1k_frames 0.3181900978088379 0.3188669681549072 0.31859670877456664 0.00021498338001451868
websocket_encode_50b_no_space_at_front_10k_frames 0.16830706596374512 0.16892695426940918 0.16877689361572265 0.000179303495145009
websocket_encode_1kb_no_space_at_front_1k_frames 0.3180549144744873 0.31873810291290283 0.3184448957443237 0.00022570351759513988
websocket_decode 0.15482807159423828 0.15525197982788086 0.15498420000076293 0.00015318580843585997

comparison

name current previous winner diff
write_http_headers 0.004857897758483887 0.004968297481536865 current -2%
bytebuffer_write_12MB_short_string_literals 0.5948729991912842 0.5945283889770507 previous 0%
bytebuffer_write_12MB_short_calculated_strings 0.5970544934272766 0.5923092007637024 previous 0%
bytebuffer_write_12MB_medium_string_literals 0.21646541357040405 0.20847909450531005 previous 3%
bytebuffer_write_12MB_medium_calculated_strings 0.23506758213043213 0.23713549375534057 current 0%
bytebuffer_write_12MB_large_calculated_strings 0.2130693793296814 0.21392449140548705 current 0%
bytebuffer_lots_of_rw 0.5337634801864624 0.5615609884262085 current -4%
bytebuffer_write_http_response_ascii_only_as_string 0.044824302196502686 0.04503010511398316 current 0%
bytebuffer_write_http_response_ascii_only_as_staticstring 0.035434603691101074 0.03534420728683472 previous 0%
bytebuffer_write_http_response_some_nonascii_as_string 0.04540679454803467 0.046186196804046634 current -1%
bytebuffer_write_http_response_some_nonascii_as_staticstring 0.035762906074523926 0.03601330518722534 current 0%
no-net_http1_10k_reqs_1_conn 0.1495995044708252 0.15215979814529418 current -1%
http1_10k_reqs_1_conn 0.6496414065361023 0.6499632954597473 previous 0%
http1_10k_reqs_100_conns 0.6508766889572144 0.6496780157089234 previous 0%
future_whenallsucceed_100k_immediately_succeeded_off_loop 0.12425729036331176 0.1265960931777954 current -1%
future_whenallsucceed_100k_immediately_succeeded_on_loop 0.12621169090270995 0.12708340883255004 current 0%
future_whenallsucceed_100k_deferred_off_loop 0.6254552960395813 0.6288611054420471 current 0%
future_whenallsucceed_100k_deferred_on_loop 0.19647581577301027 0.19576759338378907 current 0%
future_whenallcomplete_100k_immediately_succeeded_off_loop 0.10426560640335084 0.10449390411376953 current -1%
future_whenallcomplete_100k_immediately_succeeded_on_loop 0.10361130237579345 0.10400179624557496 current 0%
future_whenallcomplete_100k_deferred_off_loop 0.6099182844161988 0.6091383934020996 current 0%
future_whenallcomplete_100k_deferred_on_loop 0.1811111807823181 0.1775683045387268 previous 2%
future_reduce_10k_futures 0.05056699514389038 0.05047931671142578 previous 0%
future_reduce_into_10k_futures 0.05084251165390015 0.05011909008026123 previous 1%
channel_pipeline_1m_events 0.21969289779663087 0.2197129726409912 current 0%
websocket_encode_50b_space_at_front_1m_frames_cow 1.018279993534088 1.0395824909210205 current -2%
websocket_encode_1kb_space_at_front_100k_frames_cow 0.10436229705810547 0.10732848644256592 current -2%
websocket_encode_50b_no_space_at_front_1m_frames_cow 1.0158753991127014 1.0498322129249573 current -3%
websocket_encode_1kb_no_space_at_front_100k_frames_cow 0.10417648553848266 0.10691310167312622 current -2%
websocket_encode_50b_space_at_front_10k_frames 0.16899328231811522 0.1682772994041443 previous 0%
websocket_encode_1kb_space_at_front_1k_frames 0.31859670877456664 0.318929386138916 previous 0%
websocket_encode_50b_no_space_at_front_10k_frames 0.16877689361572265 0.16802620887756348 previous 0%
websocket_encode_1kb_no_space_at_front_1k_frames 0.3184448957443237 0.31627951860427855 previous 0%
websocket_decode 0.15498420000076293 0.15757280588150024 current -1%

significant differences found

Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

Awesome, thanks @Lukasa!

Copy link
Member

@weissi weissi left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@weissi weissi merged commit fbe0c8a into apple:master Nov 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants