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

Fixes compiler performance in mega_example. #5841

Merged
merged 1 commit into from
Apr 10, 2024

Conversation

esdrubal
Copy link
Contributor

@esdrubal esdrubal commented Apr 10, 2024

Description

ReplaceDecls for method application was calling replace_decls twice for FunctionDecl. This was visiting function declarations as a binary tree, doing replace decls twice per FunctionDecl.

With these changes, we merge both decl mappings before calling replace_decls once instead of twice.

The performance dropped from over 2min(did not wait for test to finish) to 7 seconds in the mega example. With --experimental-new-encoding and --release.

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.

@esdrubal esdrubal added compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen performance Everything related to performance, speed wise or memory wise. labels Apr 10, 2024
@esdrubal esdrubal self-assigned this Apr 10, 2024
Copy link

Benchmark for 0c46975

Click to view benchmark
Test Base PR %
code_action 5.4±0.39ms 5.6±0.17ms +3.70%
code_lens 306.8±5.67ns 288.6±10.28ns -5.93%
compile 6.3±0.07s 6.3±0.09s 0.00%
completion 4.9±0.10ms 5.0±0.13ms +2.04%
did_change_with_caching 6.1±0.13s 5.9±0.07s -3.28%
document_symbol 991.0±48.77µs 927.5±12.22µs -6.41%
format 77.8±1.24ms 77.1±2.03ms -0.90%
goto_definition 363.5±6.58µs 368.2±13.69µs +1.29%
highlight 8.8±0.10ms 9.1±0.15ms +3.41%
hover 603.1±13.13µs 609.8±28.01µs +1.11%
idents_at_position 123.2±0.34µs 122.4±2.39µs -0.65%
inlay_hints 648.3±23.87µs 660.3±13.02µs +1.85%
on_enter 485.0±12.69ns 503.0±27.87ns +3.71%
parent_decl_at_position 3.6±0.05ms 3.7±0.03ms +2.78%
prepare_rename 365.1±7.45µs 369.9±10.42µs +1.31%
rename 9.3±0.15ms 9.9±0.24ms +6.45%
semantic_tokens 1012.3±59.62µs 1047.5±12.64µs +3.48%
token_at_position 360.2±2.95µs 366.4±2.64µs +1.72%
tokens_at_position 3.6±0.06ms 3.8±0.03ms +5.56%
tokens_for_file 425.5±4.81µs 415.9±10.59µs -2.26%
traverse 52.4±2.29ms 51.1±1.54ms -2.48%

ReplaceDecls for method application was calling replace_decls twice for FunctionDecl.
This was visiting function declarations as a binary tree, doing replace decls twice per FunctionDecl.

With these changes we merge both decl mappings before calling replace_decls once instead of twice.

The performance dropped from over 2min(did not wait for test to finish) to 7 secs in the mega example. With --experimental-new-encoding and --release.
@esdrubal esdrubal force-pushed the esdrubal/fix_mega_example_performance branch from af82bc2 to 6274a78 Compare April 10, 2024 10:27
Copy link

Benchmark for 0575c7b

Click to view benchmark
Test Base PR %
code_action 5.3±0.11ms 5.6±0.24ms +5.66%
code_lens 294.7±13.19ns 289.5±11.66ns -1.76%
compile 6.2±0.08s 6.2±0.08s 0.00%
completion 4.9±0.22ms 5.5±0.48ms +12.24%
did_change_with_caching 6.2±0.06s 6.3±0.06s +1.61%
document_symbol 937.4±18.65µs 1044.3±41.20µs +11.40%
format 79.0±0.81ms 77.2±1.58ms -2.28%
goto_definition 369.1±6.68µs 369.4±13.19µs +0.08%
highlight 8.8±0.32ms 9.4±0.32ms +6.82%
hover 606.4±7.37µs 607.2±15.76µs +0.13%
idents_at_position 122.5±0.69µs 122.7±1.78µs +0.16%
inlay_hints 657.4±30.27µs 679.7±35.68µs +3.39%
on_enter 496.8±21.22ns 513.1±14.47ns +3.28%
parent_decl_at_position 3.6±0.07ms 3.8±0.12ms +5.56%
prepare_rename 364.9±6.82µs 368.8±16.59µs +1.07%
rename 9.4±0.27ms 10.0±0.52ms +6.38%
semantic_tokens 1024.0±23.69µs 1057.6±12.99µs +3.28%
token_at_position 360.0±5.83µs 363.8±5.52µs +1.06%
tokens_at_position 3.6±0.09ms 3.8±0.09ms +5.56%
tokens_for_file 412.9±6.09µs 414.4±4.40µs +0.36%
traverse 51.0±2.27ms 51.4±1.55ms +0.78%

@esdrubal esdrubal marked this pull request as ready for review April 10, 2024 10:59
@esdrubal esdrubal requested a review from a team April 10, 2024 10:59
@IGI-111 IGI-111 requested a review from a team April 10, 2024 11:23
@xunilrj xunilrj merged commit 4f12ac3 into master Apr 10, 2024
36 checks passed
@xunilrj xunilrj deleted the esdrubal/fix_mega_example_performance branch April 10, 2024 11:24
@hal3e hal3e restored the esdrubal/fix_mega_example_performance branch April 10, 2024 22:36
@hal3e hal3e deleted the esdrubal/fix_mega_example_performance branch April 11, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen performance Everything related to performance, speed wise or memory wise.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants