Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an unexpected big PR.
At the beginning, I found the semantic token highlight service can slow down the whole lsp server, and eats a lot of memory over time. I think that because there are too much semantic token requests to be processed. So I want to move it into
build-trace%
class, make it runs along with check syntax task, and reduce the number of requests.The problem is that the semantic token request needs to be processed concurrently, and I need to add locks to a lot of code. Most changes in this PR come from the locked code.
To make the concurrent code intuitive and simple, I also considered the design again.
In this design, All requests are classified to two types of nodes:
As the graph shows:
Any new request is either a new text node or a new query node that depends on the current text node.
The text node updates synchronously then runs a check syntax task asynchronously. Most queries also runs synchronously as before. But for async queries (only semantic token service currently), they are scheduled to run before the next text change event or after its check syntax task completed. So there are two events to trigger the process of the async queries.
In other words, a text change will clear all old queries, a successful check syntax task can also clear all old queries.
I also refactored the
build-trace%
class using visitor pattern. And added comment tomethods.rkt
to introduce the design.The result is that the overall latency is back to previous level and the semantic tokens is faster to response.
The cached expand I added in my previous PR is useless now, but it might be useful to speedup the check syntax task in the future, so I didn't remove it.