Moves all Dispatchers.Default to IO because of the amount of Synchronized code that blocks the thread underneath each coroutine and since Default only has the exact number of threads the processor offers, once they block, we lose computing power

This commit is contained in:
Vitor Pamplona
2025-10-21 18:30:08 -04:00
parent d8907e3dfb
commit df54f7bb67
112 changed files with 231 additions and 231 deletions
@@ -108,7 +108,7 @@ class NostrClient(
}.sample(300)
.onEach {
relayPool.updatePool(it)
}.flowOn(Dispatchers.Default)
}.flowOn(Dispatchers.IO)
.stateIn(
scope,
SharingStarted.Eagerly,
@@ -229,7 +229,7 @@ class NostrClient(
override fun renewFilters(relay: IRelayClient) {
if (isActive) {
scope.launch(Dispatchers.Default) {
scope.launch(Dispatchers.IO) {
activeRequests.syncState(relay.url, relay::sendOrConnectAndSync)
activeCounts.syncState(relay.url, relay::sendOrConnectAndSync)
eventOutbox.syncState(relay.url, relay::sendOrConnectAndSync)
@@ -60,7 +60,7 @@ class BasicOkHttpWebSocket(
val listener =
object : OkHttpWebSocketListener() {
val scope = CoroutineScope(Dispatchers.Default + exceptionHandler)
val scope = CoroutineScope(Dispatchers.IO + exceptionHandler)
val incomingMessages: Channel<String> = Channel(Channel.UNLIMITED)
val job = // Launch a coroutine to process messages from the channel.
scope.launch {