mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 03:32:38 +08:00
perf: 使用线程池而非协程处理 IO 事件。
在 pixel6 测试,协程启动耗时约 0.5-1ms,线程池约 0.02-0.1ms。
This commit is contained in:
parent
933fd91d08
commit
5e8e610efa
|
@ -57,6 +57,7 @@ import li.songe.gkd.util.subsItemsFlow
|
|||
import li.songe.gkd.util.updateStorage
|
||||
import li.songe.gkd.util.updateSubscription
|
||||
import li.songe.selector.Selector
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
|
@ -124,7 +125,7 @@ class GkdAbService : CompositionAbService({
|
|||
var lastTriggerShizukuTime = 0L
|
||||
var lastContentEventTime = 0L
|
||||
val queryThread = Dispatchers.IO.limitedParallelism(1)
|
||||
val eventThread = Dispatchers.IO.limitedParallelism(1)
|
||||
val eventExecutor = Executors.newSingleThreadExecutor()
|
||||
onDestroy {
|
||||
queryThread.cancel()
|
||||
}
|
||||
|
@ -207,7 +208,7 @@ class GkdAbService : CompositionAbService({
|
|||
val evActivityId = fixedEvent.className
|
||||
|
||||
|
||||
scope.launch(eventThread) {
|
||||
eventExecutor.execute launch@{
|
||||
val eventNode = event.source ?: return@launch
|
||||
val oldAppId = topActivityFlow.value.appId
|
||||
val rightAppId = if (oldAppId == evAppId) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user