Skip to content
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

Improving binary size for encoding v1 #6096

Merged
merged 11 commits into from
Jun 21, 2024
Merged

Conversation

xunilrj
Copy link
Contributor

@xunilrj xunilrj commented Jun 6, 2024

Description

This PR implements five optimizations to decrease the binary size of contracts:

1 - create BufferReader only once;
2 - BufferReader using only one pointer to the current position;
3 - more specialized read fns for BufferReader;
4 - remove useless binary operations;
5 - do not encode the result of a contract method, if it is ().

Which brings the contract test_fuel_coin_contract from 3400 to 2560 bytes. Around 25% improvement. Results will be more timid for bigger contracts.

image

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@xunilrj xunilrj requested a review from a team as a code owner June 6, 2024 14:42
@xunilrj xunilrj self-assigned this Jun 6, 2024
Copy link

github-actions bot commented Jun 6, 2024

Benchmark for 4620a68

Click to view benchmark
Test Base PR %
code_action 5.4±0.23ms 5.2±0.11ms -3.70%
code_lens 337.4±12.91ns 334.4±10.81ns -0.89%
compile 4.0±0.08s 4.1±0.08s +2.50%
completion 4.8±0.07ms 4.6±0.12ms -4.17%
did_change_with_caching 3.7±0.07s 3.7±0.05s 0.00%
document_symbol 1032.0±45.46µs 988.5±45.00µs -4.22%
format 73.1±1.73ms 74.4±1.09ms +1.78%
goto_definition 361.0±4.21µs 367.6±6.64µs +1.83%
highlight 9.0±0.04ms 8.7±0.19ms -3.33%
hover 539.4±7.17µs 541.5±9.50µs +0.39%
idents_at_position 123.8±0.26µs 122.5±0.49µs -1.05%
inlay_hints 668.1±20.12µs 663.4±47.09µs -0.70%
on_enter 462.3±13.62ns 451.4±12.35ns -2.36%
parent_decl_at_position 3.7±0.02ms 3.6±0.04ms -2.70%
prepare_rename 359.0±6.22µs 364.3±6.59µs +1.48%
rename 9.6±0.32ms 9.3±0.12ms -3.12%
semantic_tokens 982.3±13.06µs 978.5±30.28µs -0.39%
token_at_position 360.3±2.45µs 353.3±2.66µs -1.94%
tokens_at_position 3.7±0.03ms 3.6±0.04ms -2.70%
tokens_for_file 431.0±1.29µs 432.8±8.14µs +0.42%
traverse 39.4±1.54ms 40.0±1.45ms +1.52%

Copy link

github-actions bot commented Jun 7, 2024

Benchmark for 8147e89

Click to view benchmark
Test Base PR %
code_action 5.3±0.29ms 5.4±0.10ms +1.89%
code_lens 287.3±16.63ns 286.8±15.07ns -0.17%
compile 4.0±0.07s 4.1±0.06s +2.50%
completion 4.7±0.42ms 4.8±0.27ms +2.13%
did_change_with_caching 3.7±0.07s 3.8±0.14s +2.70%
document_symbol 979.3±20.16µs 967.8±16.23µs -1.17%
format 72.3±2.38ms 71.9±1.38ms -0.55%
goto_definition 483.8±221.85µs 429.1±9.42µs -11.31%
highlight 8.9±0.58ms 9.1±0.02ms +2.25%
hover 543.4±7.21µs 600.8±14.34µs +10.56%
idents_at_position 124.7±0.60µs 124.4±1.75µs -0.24%
inlay_hints 655.0±14.99µs 720.6±20.52µs +10.02%
on_enter 472.0±16.65ns 470.4±12.78ns -0.34%
parent_decl_at_position 3.6±0.10ms 3.7±0.11ms +2.78%
prepare_rename 366.6±3.58µs 426.6±8.05µs +16.37%
rename 9.3±0.06ms 9.8±0.55ms +5.38%
semantic_tokens 989.3±60.25µs 991.3±31.41µs +0.20%
token_at_position 364.2±2.15µs 365.1±2.86µs +0.25%
tokens_at_position 3.6±0.04ms 3.7±0.06ms +2.78%
tokens_for_file 418.7±14.87µs 422.7±7.61µs +0.96%
traverse 41.4±1.36ms 41.5±1.62ms +0.24%

sway-lib-core/src/codec.sw Outdated Show resolved Hide resolved
@xunilrj xunilrj requested a review from a team as a code owner June 7, 2024 16:52
Copy link

github-actions bot commented Jun 7, 2024

Benchmark for e190f83

Click to view benchmark
Test Base PR %
code_action 5.3±0.11ms 5.3±0.14ms 0.00%
code_lens 288.6±11.58ns 292.2±15.93ns +1.25%
compile 3.9±0.08s 4.0±0.10s +2.56%
completion 4.6±0.02ms 4.6±0.01ms 0.00%
did_change_with_caching 3.6±0.08s 3.7±0.10s +2.78%
document_symbol 966.4±17.03µs 953.1±22.86µs -1.38%
format 71.3±0.63ms 71.0±1.59ms -0.42%
goto_definition 361.8±3.54µs 363.5±3.17µs +0.47%
highlight 8.6±0.02ms 8.8±0.40ms +2.33%
hover 538.4±4.46µs 539.5±17.76µs +0.20%
idents_at_position 122.9±0.81µs 123.3±1.03µs +0.33%
inlay_hints 653.1±21.07µs 652.1±11.10µs -0.15%
on_enter 464.5±16.26ns 476.8±13.54ns +2.65%
parent_decl_at_position 3.6±0.03ms 3.6±0.01ms 0.00%
prepare_rename 365.8±8.94µs 365.1±15.63µs -0.19%
rename 9.3±0.25ms 9.4±0.28ms +1.08%
semantic_tokens 966.9±32.08µs 995.5±19.07µs +2.96%
token_at_position 356.1±12.14µs 365.5±2.03µs +2.64%
tokens_at_position 3.6±0.03ms 3.6±0.04ms 0.00%
tokens_for_file 425.0±3.20µs 422.2±2.32µs -0.66%
traverse 40.5±0.97ms 41.5±2.05ms +2.47%

@xunilrj xunilrj requested a review from a team as a code owner June 8, 2024 07:31
Copy link

github-actions bot commented Jun 8, 2024

Benchmark for fbc6599

Click to view benchmark
Test Base PR %
code_action 5.3±0.25ms 5.3±0.02ms 0.00%
code_lens 288.2±11.69ns 299.4±8.99ns +3.89%
compile 4.0±0.05s 4.1±0.13s +2.50%
completion 4.7±0.15ms 4.7±0.08ms 0.00%
did_change_with_caching 3.7±0.09s 3.7±0.06s 0.00%
document_symbol 980.2±16.96µs 1018.9±20.86µs +3.95%
format 70.7±1.25ms 70.9±1.18ms +0.28%
goto_definition 360.2±4.71µs 366.5±5.27µs +1.75%
highlight 8.8±0.30ms 8.8±0.03ms 0.00%
hover 542.4±5.35µs 544.6±7.00µs +0.41%
idents_at_position 121.8±1.32µs 121.9±0.53µs +0.08%
inlay_hints 660.8±24.58µs 650.3±16.79µs -1.59%
on_enter 470.8±9.89ns 481.3±20.56ns +2.23%
parent_decl_at_position 3.6±0.03ms 3.7±0.27ms +2.78%
prepare_rename 359.3±6.07µs 368.0±7.22µs +2.42%
rename 9.4±0.28ms 9.4±0.18ms 0.00%
semantic_tokens 940.3±22.62µs 1006.5±21.90µs +7.04%
token_at_position 359.5±2.15µs 372.2±1.73µs +3.53%
tokens_at_position 3.6±0.06ms 3.7±0.07ms +2.78%
tokens_for_file 420.6±4.27µs 423.6±2.57µs +0.71%
traverse 40.3±1.78ms 40.8±1.45ms +1.24%

IGI-111
IGI-111 previously approved these changes Jun 10, 2024
@IGI-111 IGI-111 requested a review from vaivaswatha June 10, 2024 07:31
Copy link

Benchmark for eeff563

Click to view benchmark
Test Base PR %
code_action 5.3±0.13ms 5.3±0.46ms 0.00%
code_lens 289.8±7.79ns 287.7±7.58ns -0.72%
compile 4.0±0.10s 4.0±0.08s 0.00%
completion 4.6±0.08ms 4.6±0.14ms 0.00%
did_change_with_caching 3.6±0.09s 3.6±0.08s 0.00%
document_symbol 986.1±38.05µs 948.7±14.08µs -3.79%
format 72.5±1.43ms 71.2±1.58ms -1.79%
goto_definition 358.9±4.42µs 372.8±13.46µs +3.87%
highlight 8.7±0.16ms 8.8±0.08ms +1.15%
hover 531.8±13.68µs 546.3±20.13µs +2.73%
idents_at_position 122.7±0.47µs 122.9±0.84µs +0.16%
inlay_hints 648.1±12.07µs 663.0±61.42µs +2.30%
on_enter 469.1±12.63ns 479.2±16.33ns +2.15%
parent_decl_at_position 3.6±0.03ms 3.6±0.05ms 0.00%
prepare_rename 358.5±5.10µs 369.8±5.99µs +3.15%
rename 9.3±0.21ms 9.4±0.03ms +1.08%
semantic_tokens 967.7±14.61µs 974.6±26.01µs +0.71%
token_at_position 362.7±3.21µs 361.9±7.93µs -0.22%
tokens_at_position 3.6±0.02ms 3.6±0.06ms 0.00%
tokens_for_file 422.4±14.64µs 428.3±3.21µs +1.40%
traverse 39.0±1.40ms 40.2±1.95ms +3.08%

@xunilrj xunilrj force-pushed the xunilrj/encoding-v1-optimize-size branch 2 times, most recently from fabc945 to d4cb2c3 Compare June 10, 2024 15:55
Copy link

Benchmark for 0c2b493

Click to view benchmark
Test Base PR %
code_action 5.3±0.02ms 5.5±0.15ms +3.77%
code_lens 284.7±8.35ns 292.3±7.21ns +2.67%
compile 4.1±0.08s 4.1±0.07s 0.00%
completion 4.7±0.15ms 4.8±0.11ms +2.13%
did_change_with_caching 3.8±0.06s 3.9±0.06s +2.63%
document_symbol 1000.4±45.03µs 1018.4±63.17µs +1.80%
format 72.5±1.69ms 72.5±1.06ms 0.00%
goto_definition 368.9±5.63µs 373.6±9.66µs +1.27%
highlight 8.8±0.23ms 9.0±0.20ms +2.27%
hover 545.6±12.91µs 552.1±10.41µs +1.19%
idents_at_position 124.0±0.79µs 122.9±1.91µs -0.89%
inlay_hints 653.7±23.09µs 666.0±31.65µs +1.88%
on_enter 461.2±11.72ns 489.8±13.27ns +6.20%
parent_decl_at_position 3.6±0.07ms 3.7±0.03ms +2.78%
prepare_rename 368.5±7.09µs 378.0±11.06µs +2.58%
rename 9.5±0.26ms 9.7±0.50ms +2.11%
semantic_tokens 978.1±14.59µs 1001.8±14.88µs +2.42%
token_at_position 363.2±3.46µs 368.8±6.85µs +1.54%
tokens_at_position 3.6±0.04ms 3.7±0.09ms +2.78%
tokens_for_file 424.1±2.21µs 425.8±2.81µs +0.40%
traverse 42.1±1.04ms 42.0±1.22ms -0.24%

Copy link

Benchmark for b35e0c0

Click to view benchmark
Test Base PR %
code_action 5.1±0.09ms 5.2±0.02ms +1.96%
code_lens 288.2±19.12ns 287.1±10.35ns -0.38%
compile 3.4±0.08s 3.4±0.09s 0.00%
completion 4.6±0.02ms 4.8±0.11ms +4.35%
did_change_with_caching 3.2±0.07s 3.1±0.06s -3.13%
document_symbol 931.9±11.17µs 1018.3±24.91µs +9.27%
format 70.2±0.58ms 72.4±0.72ms +3.13%
goto_definition 354.8±7.67µs 358.2±4.61µs +0.96%
highlight 8.8±0.19ms 9.0±0.03ms +2.27%
hover 579.6±7.85µs 583.5±3.88µs +0.67%
idents_at_position 120.3±0.72µs 120.5±1.23µs +0.17%
inlay_hints 643.3±16.87µs 670.9±35.10µs +4.29%
on_enter 467.4±16.33ns 491.5±16.71ns +5.16%
parent_decl_at_position 3.6±0.02ms 3.7±0.02ms +2.78%
prepare_rename 355.3±7.21µs 359.8±6.56µs +1.27%
rename 9.0±0.14ms 9.2±0.04ms +2.22%
semantic_tokens 943.8±44.53µs 965.7±24.90µs +2.32%
token_at_position 348.4±3.67µs 350.4±2.76µs +0.57%
tokens_at_position 3.6±0.04ms 3.7±0.04ms +2.78%
tokens_for_file 436.5±7.41µs 410.9±1.84µs -5.86%
traverse 36.6±0.82ms 36.8±0.54ms +0.55%

@xunilrj xunilrj requested review from jjcnn and IGI-111 June 11, 2024 07:51
@xunilrj xunilrj force-pushed the xunilrj/encoding-v1-optimize-size branch from 61e0d32 to 94257d4 Compare June 11, 2024 14:15
Copy link

Benchmark for 94f4145

Click to view benchmark
Test Base PR %
code_action 5.1±0.01ms 5.2±0.07ms +1.96%
code_lens 349.1±7.08ns 336.0±7.67ns -3.75%
compile 3.4±0.09s 3.4±0.10s 0.00%
completion 4.7±0.36ms 4.8±0.09ms +2.13%
did_change_with_caching 3.2±0.10s 3.2±0.08s 0.00%
document_symbol 937.1±12.80µs 934.2±24.75µs -0.31%
format 88.3±1.22ms 89.2±1.14ms +1.02%
goto_definition 351.4±10.44µs 358.4±10.31µs +1.99%
highlight 8.7±0.16ms 9.1±0.64ms +4.60%
hover 580.5±8.14µs 578.8±5.24µs -0.29%
idents_at_position 121.5±0.25µs 119.7±0.90µs -1.48%
inlay_hints 678.0±9.66µs 661.4±11.62µs -2.45%
on_enter 455.7±15.70ns 468.6±13.50ns +2.83%
parent_decl_at_position 3.6±0.05ms 3.7±0.03ms +2.78%
prepare_rename 349.2±5.55µs 353.6±7.13µs +1.26%
rename 8.9±0.15ms 9.3±0.15ms +4.49%
semantic_tokens 973.8±16.55µs 971.5±34.46µs -0.24%
token_at_position 349.5±5.48µs 340.5±3.17µs -2.58%
tokens_at_position 3.6±0.06ms 3.7±0.03ms +2.78%
tokens_for_file 410.0±11.83µs 414.1±4.01µs +1.00%
traverse 36.3±0.51ms 35.8±0.61ms -1.38%

IGI-111
IGI-111 previously approved these changes Jun 13, 2024
@IGI-111 IGI-111 requested a review from a team June 13, 2024 10:31
Copy link

Benchmark for 89101b5

Click to view benchmark
Test Base PR %
code_action 5.1±0.04ms 5.3±0.21ms +3.92%
code_lens 348.4±10.82ns 353.8±10.29ns +1.55%
compile 3.4±0.07s 3.4±0.08s 0.00%
completion 4.6±0.01ms 5.0±0.20ms +8.70%
did_change_with_caching 3.2±0.07s 3.2±0.10s 0.00%
document_symbol 952.6±19.09µs 956.8±25.40µs +0.44%
format 88.2±0.70ms 90.6±1.47ms +2.72%
goto_definition 349.9±8.88µs 352.8±10.01µs +0.83%
highlight 8.7±0.33ms 9.0±0.03ms +3.45%
hover 569.9±6.80µs 581.3±12.57µs +2.00%
idents_at_position 120.5±0.36µs 120.3±1.73µs -0.17%
inlay_hints 753.4±12.64µs 653.1±9.01µs -13.31%
on_enter 468.2±9.74ns 460.4±9.08ns -1.67%
parent_decl_at_position 3.8±0.41ms 3.7±0.12ms -2.63%
prepare_rename 349.2±5.50µs 350.9±9.36µs +0.49%
rename 8.9±0.14ms 9.3±0.21ms +4.49%
semantic_tokens 959.7±16.54µs 980.6±23.10µs +2.18%
token_at_position 354.1±5.12µs 352.0±2.31µs -0.59%
tokens_at_position 3.9±0.44ms 3.7±0.06ms -5.13%
tokens_for_file 410.5±2.25µs 411.3±4.52µs +0.19%
traverse 35.9±0.58ms 37.6±1.44ms +4.74%

@xunilrj xunilrj force-pushed the xunilrj/encoding-v1-optimize-size branch from 7271618 to abc4774 Compare June 20, 2024 11:03
Copy link

Benchmark for 6a6603c

Click to view benchmark
Test Base PR %
code_action 5.2±0.11ms 5.1±0.10ms -1.92%
code_lens 294.1±14.70ns 288.8±13.31ns -1.80%
compile 3.4±0.09s 3.5±0.08s +2.94%
completion 4.8±0.05ms 4.6±0.25ms -4.17%
did_change_with_caching 3.1±0.06s 3.2±0.09s +3.23%
document_symbol 894.1±43.61µs 910.9±49.57µs +1.88%
format 87.4±1.56ms 88.2±0.75ms +0.92%
goto_definition 342.6±12.99µs 342.0±18.53µs -0.18%
highlight 9.1±0.19ms 8.7±0.34ms -4.40%
hover 568.3±5.72µs 564.4±7.58µs -0.69%
idents_at_position 117.9±0.64µs 119.8±1.02µs +1.61%
inlay_hints 643.7±23.76µs 634.8±30.02µs -1.38%
on_enter 491.3±28.07ns 456.3±12.44ns -7.12%
parent_decl_at_position 3.8±0.13ms 3.6±0.04ms -5.26%
prepare_rename 338.6±6.77µs 342.7±15.41µs +1.21%
rename 9.3±0.02ms 9.1±0.20ms -2.15%
semantic_tokens 1277.5±63.77µs 1277.0±14.49µs -0.04%
token_at_position 334.0±3.98µs 336.3±3.04µs +0.69%
tokens_at_position 3.7±0.04ms 3.6±0.07ms -2.70%
tokens_for_file 396.7±1.12µs 400.0±4.35µs +0.83%
traverse 35.9±0.71ms 36.8±0.54ms +2.51%

Copy link

Benchmark for fc86247

Click to view benchmark
Test Base PR %
code_action 5.2±0.10ms 5.1±0.11ms -1.92%
code_lens 292.5±9.24ns 290.6±9.83ns -0.65%
compile 3.5±0.07s 3.5±0.08s 0.00%
completion 4.8±0.03ms 4.7±0.04ms -2.08%
did_change_with_caching 3.3±0.07s 3.3±0.05s 0.00%
document_symbol 887.7±48.23µs 858.6±21.72µs -3.28%
format 88.5±1.35ms 88.4±1.43ms -0.11%
goto_definition 338.2±6.13µs 340.3±6.64µs +0.62%
highlight 9.0±0.17ms 8.8±0.26ms -2.22%
hover 557.8±10.58µs 562.7±7.19µs +0.88%
idents_at_position 117.4±0.43µs 120.8±0.53µs +2.90%
inlay_hints 637.3±22.12µs 627.2±25.96µs -1.58%
on_enter 465.5±8.25ns 465.7±17.92ns +0.04%
parent_decl_at_position 3.7±0.03ms 3.6±0.05ms -2.70%
prepare_rename 335.4±9.36µs 341.7±7.04µs +1.88%
rename 9.5±0.17ms 9.0±0.16ms -5.26%
semantic_tokens 1269.4±18.45µs 1236.6±9.95µs -2.58%
token_at_position 333.6±1.79µs 336.6±3.60µs +0.90%
tokens_at_position 3.7±0.05ms 3.6±0.05ms -2.70%
tokens_for_file 400.0±7.08µs 398.9±2.29µs -0.28%
traverse 37.0±0.47ms 37.5±0.92ms +1.35%

@xunilrj xunilrj requested a review from IGI-111 June 20, 2024 12:39
Copy link

Benchmark for 9981ce6

Click to view benchmark
Test Base PR %
code_action 5.5±0.57ms 5.3±0.16ms -3.64%
code_lens 288.2±8.84ns 289.2±8.00ns +0.35%
compile 3.7±0.06s 3.7±0.08s 0.00%
completion 5.0±0.26ms 5.0±0.20ms 0.00%
did_change_with_caching 3.5±0.08s 3.5±0.07s 0.00%
document_symbol 943.5±43.52µs 874.3±15.02µs -7.33%
format 88.3±1.19ms 88.3±2.53ms 0.00%
goto_definition 340.7±3.96µs 343.7±11.72µs +0.88%
highlight 8.9±0.30ms 8.9±0.15ms 0.00%
hover 573.7±9.08µs 569.4±7.30µs -0.75%
idents_at_position 118.2±0.64µs 119.7±1.27µs +1.27%
inlay_hints 636.3±31.28µs 645.6±38.12µs +1.46%
on_enter 480.2±8.38ns 460.8±13.00ns -4.04%
parent_decl_at_position 3.6±0.06ms 3.6±0.06ms 0.00%
prepare_rename 341.1±7.81µs 343.0±6.71µs +0.56%
rename 9.4±0.34ms 9.4±0.28ms 0.00%
semantic_tokens 1262.3±22.73µs 1301.9±12.92µs +3.14%
token_at_position 334.6±2.54µs 342.4±2.57µs +2.33%
tokens_at_position 3.7±0.10ms 3.6±0.05ms -2.70%
tokens_for_file 400.2±2.81µs 399.5±2.46µs -0.17%
traverse 39.3±0.69ms 39.3±0.47ms 0.00%

@IGI-111 IGI-111 merged commit 3b142d5 into master Jun 21, 2024
38 checks passed
@IGI-111 IGI-111 deleted the xunilrj/encoding-v1-optimize-size branch June 21, 2024 09:21
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.

None yet

5 participants