perf: slightly less latency for keyboard/mouse/os events

This commit is contained in:
Louis Pontoise authored and lwouis committed 2020-08-04 00:47:01 +09:00
1 parent 26e840c1e7
commit 28fb5f4afa
2 files changed
+17 -4

No files matched your search

+12
View File
@@ -115,3 +115,15 @@ func assignIfDifferent<T: Equatable>(_ a: UnsafeMutablePointer<T>, _ b: T) {
a.pointee = b
}
}
extension DispatchQoS {
func toQualityOfService() -> QualityOfService {
switch self {
case .userInteractive: return .userInteractive
case .userInitiated: return .userInitiated
case .utility: return .utility
case .background: return .background
default: return .default
}
}
}
+5 -4
View File
@@ -19,9 +19,9 @@ class BackgroundWork {
accessibilityCommandsQueue = DispatchQueue.globalConcurrent("accessibilityCommandsQueue", .userInteractive)
axCallsQueue = DispatchQueue.globalConcurrent("axCallsQueue", .userInteractive)
crashReportsQueue = DispatchQueue.globalConcurrent("crashReportsQueue", .utility)
accessibilityEventsThread = BackgroundThreadWithRunLoop("accessibilityEventsThread")
keyboardEventsThread = BackgroundThreadWithRunLoop("keyboardEventsThread")
mouseEventsThread = BackgroundThreadWithRunLoop("mouseEventsThread")
accessibilityEventsThread = BackgroundThreadWithRunLoop("accessibilityEventsThread", .userInteractive)
keyboardEventsThread = BackgroundThreadWithRunLoop("keyboardEventsThread", .userInteractive)
mouseEventsThread = BackgroundThreadWithRunLoop("mouseEventsThread", .userInteractive)
}
}
@@ -48,7 +48,7 @@ class BackgroundThreadWithRunLoop {
var thread: Thread?
var runLoop: CFRunLoop?
init(_ name: String) {
init(_ name: String, _ qos: DispatchQoS) {
thread = Thread {
self.runLoop = CFRunLoopGetCurrent()
while !self.thread!.isCancelled {
@@ -58,6 +58,7 @@ class BackgroundThreadWithRunLoop {
}
}
thread!.name = name
thread!.qualityOfService = qos.toQualityOfService()
thread!.start()
}
}