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

Implement a more responsive compilation thread in the the language server. #5429

Merged
merged 42 commits into from
Jan 8, 2024

Conversation

JoshuaBatty
Copy link
Member

@JoshuaBatty JoshuaBatty commented Jan 4, 2024

Description

This PR implements options 2 & 4 from #4706 in order to drastically improve responsiveness to did change events in the server. We now spawn a dedicated compilation thread to respond and process events in parallel. The compiler now periodically checks if the server has requested it bail out to start compilation on a newer event. I've tried to limit the number of places we perform this check to reduce code "noise".

We also clone the Engines before compiling and write the result back to the Engines held by the server on a successful compilation. This is to avoid the Engines becoming corrupted if the server requests the compiler to bail out early.

Some other small changes:

  • Diagnostics are now only published on didSave events
  • Semantic tokens are only computed for the visible range and not the entire document

Here are the before and after results when running the did_change_stress_test when responding to 400 compilation requests on the benchmark project: 🚀

Metric Before After Speedup Factor
Each Request Time 78.265ms 360.03µs 217x
Total Time 31.7856242s 1.54047762s 20x

Previously, we had to wait until compilation had finished before we could respond to incoming events. Now that compilation is done in parallel, we can respond to new events (and set the re-trigger compilation flag) as quickly as possible. This leads to a pretty noticeable improvement to the UX when typing in the editor.

closes #4706

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.

@JoshuaBatty JoshuaBatty marked this pull request as draft January 4, 2024 03:44
@JoshuaBatty JoshuaBatty force-pushed the josh/compiler_thread branch 2 times, most recently from fe2512c to b9b6ca6 Compare January 4, 2024 23:49
@JoshuaBatty JoshuaBatty self-assigned this Jan 5, 2024
@JoshuaBatty JoshuaBatty added language server LSP server compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen labels Jan 5, 2024
@JoshuaBatty JoshuaBatty force-pushed the josh/compiler_thread branch from bfd6eb3 to acff1b4 Compare January 5, 2024 03:25
@JoshuaBatty JoshuaBatty requested review from a team January 5, 2024 03:42
@JoshuaBatty JoshuaBatty marked this pull request as ready for review January 5, 2024 03:43
tritao
tritao previously approved these changes Jan 5, 2024
Copy link
Contributor

@tritao tritao left a comment

Choose a reason for hiding this comment

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

Nice work, great to see this, new architecture looking awesome.
Just a few minor nits.

@JoshuaBatty JoshuaBatty force-pushed the josh/compiler_thread branch from 4078281 to 95022ee Compare January 7, 2024 23:15
@JoshuaBatty JoshuaBatty requested review from tritao and a team January 7, 2024 23:52
@JoshuaBatty
Copy link
Member Author

Thanks for the review @tritao , mem swaps FTW! Should be good to go now.

@JoshuaBatty JoshuaBatty requested a review from a team January 8, 2024 10:31
@JoshuaBatty JoshuaBatty enabled auto-merge (squash) January 8, 2024 10:32
Copy link
Member

@sdankel sdankel left a comment

Choose a reason for hiding this comment

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

LGTM

@JoshuaBatty JoshuaBatty merged commit a164fe1 into master Jan 8, 2024
34 checks passed
@JoshuaBatty JoshuaBatty deleted the josh/compiler_thread branch January 8, 2024 23:53
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 language server LSP server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimizing did_change Callbacks for Responsive Compilation
3 participants