Repository navigation
Async TreeSitterClient - #191
Merged
thecoolwinter merged 10 commits intoJun 3, 2023
Merged
Conversation
Removes a lot of deadlocks from the initial implementation using locks. Also imports the `os` system library to use the newer `OSAllocatedUnfairLock` type for speed.
matthijseikelenboom
left a comment
Contributor
There was a problem hiding this comment.
Excellent work!
In the future, we might need to make dedicated documentation for this repo. It's getting quite complicated by just reading the code. So maybe adding diagrams or other visual media might be an idea.
0xWDG
previously approved these changes
Jun 3, 2023
matthijseikelenboom
approved these changes
Jun 3, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Modifies
TreeSitterClientto support doing work on a background thread when doing so is beneficial. This allows the editor to display content while languages load, scroll smoothly while highlight queries perform in the background, and on large documents perform edits asynchronously to keep UI responsive.Edits and highlights are only queued for background work when:
Constants.parserTimeout) and a parser times out.Constants.maxSyncEditLength,Constants.maxSyncQueryLength)Constants.maxSyncContentLength)Changes:
TreeSitterStateobject that handles managing the language layer tree (language layers renamed toLanguageLayer)PthreadLockfor efficient, thread-safe locking via a wrappedpthread_mutex.applyEditandqueryHighlightsForqueuedEditsandqueuedQueriesto hold any enqueued edits and queries.stateLock: Must be acquired before performing any actions on the state objectqueueLock: Must be acquired before modifying the previously mentioned queues.runningTask:beginTasksIfNeededstarts the background task if there is any outstanding work and there is no existing task.determineNextJobdequeues a job(s) to perform in the background task. Handles job ordering and greedily dequeues highlight jobs as determined byConstants.simultaneousHighlightLimitcancelAllRunningTaskscancels the running task and removes all queued jobs.Related Issues
Checklist
Screenshots
Async language loading. Swift has a terrible initial loading time and this recording shows that the document now opens instantly but performs the initial work on a background thread. Note that this initial loading time is nearly nonexistent in subsequent document loads due to the queries being cached.
Previously, this would have blocked the main thread for the entire duration of the language load (up to 5s in my testing).
Screen.Recording.2023-06-03.at.1.33.01.AM.mov
Async highlighting means extremely long documents can load and highlight without affecting displaying and scrolling. This is still slightly "hitch"-y due to NSTextStorage performance when applying highlight data to the text view.
Screen.Recording.2023-06-03.at.1.33.34.AM.mov