File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
Sources/CodeEditSourceEditor/TreeSitter Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -82,18 +82,24 @@ public final class TreeSitterClient: HighlightProviding {
8282 /// The number of characters to read in a read block.
8383 ///
8484 /// This has diminishing returns on the number of times the read block is called as this number gets large.
85- public static var charsToReadInBlock : Int = 4096
85+ public static let charsToReadInBlock : Int = 4096
8686
8787 /// The duration before a long parse notification is sent.
8888 public static var longParseTimeout : Duration = . seconds( 0.5 )
8989
9090 /// The notification name sent when a long parse is detected.
91- public static var longParse : Notification . Name = . init( " CodeEditSourceEditor.longParseNotification " )
91+ public static let longParse : Notification . Name = . init( " CodeEditSourceEditor.longParseNotification " )
9292
9393 /// The notification name sent when a long parse is finished.
94- public static var longParseFinished : Notification . Name = . init(
94+ public static let longParseFinished : Notification . Name = . init(
9595 " CodeEditSourceEditor.longParseFinishedNotification "
9696 )
97+
98+ /// The duration tasks sleep before checking if they're runnable.
99+ ///
100+ /// Lower than 1ms starts causing bad lock contention, much higher reduces responsiveness with diminishing
101+ /// returns on CPU efficiency.
102+ public static let taskSleepDuration : Duration = . milliseconds( 10 )
97103 }
98104
99105 // MARK: - HighlightProviding
Original file line number Diff line number Diff line change @@ -61,9 +61,7 @@ final package class TreeSitterExecutor {
6161 let task = Task ( priority: . userInitiated) { // This executes outside the lock's control.
6262 while self . lock. withLock ( { !canTaskExec( id: id, priority: priority) } ) {
6363 // Instead of yielding, sleeping frees up the CPU due to time off the CPU and less lock contention
64- // lower than 1ms starts causing lock contention, much higher reduces responsiveness with diminishing
65- // returns on CPU efficiency.
66- try ? await Task . sleep ( for: . milliseconds( 1 ) )
64+ try ? await Task . sleep ( for: TreeSitterClient . Constants. taskSleepDuration)
6765 guard !Task. isCancelled else {
6866 removeTask ( id)
6967 onCancel ( )
You can’t perform that action at this time.
0 commit comments