From d2ca94f60e264155db9a4af014a8faa638a5f6ae Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Mon, 18 Sep 2023 14:09:14 -0400 Subject: [PATCH] Consistently set 8 MiB stack sizes on all platforms --- .../cash/redwood/treehouse/AndroidTreehouseDispatchers.kt | 2 +- .../app/cash/redwood/treehouse/TreehouseDispatchers.kt | 6 ++++++ .../app/cash/redwood/treehouse/IosTreehouseDispatchers.kt | 4 +--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/redwood-treehouse-host/src/androidMain/kotlin/app/cash/redwood/treehouse/AndroidTreehouseDispatchers.kt b/redwood-treehouse-host/src/androidMain/kotlin/app/cash/redwood/treehouse/AndroidTreehouseDispatchers.kt index 0a0bcc566a..0f3f0e3e66 100644 --- a/redwood-treehouse-host/src/androidMain/kotlin/app/cash/redwood/treehouse/AndroidTreehouseDispatchers.kt +++ b/redwood-treehouse-host/src/androidMain/kotlin/app/cash/redwood/treehouse/AndroidTreehouseDispatchers.kt @@ -30,7 +30,7 @@ internal class AndroidTreehouseDispatchers : TreehouseDispatchers { /** The single thread that runs all JavaScript. We only have one QuickJS instance at a time. */ private val executorService = Executors.newSingleThreadExecutor { runnable -> - Thread(runnable, "Treehouse") + Thread(null, runnable, "Treehouse", ZIPLINE_THREAD_STACK_SIZE.toLong()) .also { ziplineThread = it } } diff --git a/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/TreehouseDispatchers.kt b/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/TreehouseDispatchers.kt index ce0d39c203..88be6596a9 100644 --- a/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/TreehouseDispatchers.kt +++ b/redwood-treehouse-host/src/commonMain/kotlin/app/cash/redwood/treehouse/TreehouseDispatchers.kt @@ -54,3 +54,9 @@ public interface TreehouseDispatchers { */ public fun close() } + +/** + * We configure an 8 MiB thread size because we've experimentally found that's sufficient for our + * guest programs. + */ +internal val ZIPLINE_THREAD_STACK_SIZE = 8 * 1024 * 1024 diff --git a/redwood-treehouse-host/src/iosMain/kotlin/app/cash/redwood/treehouse/IosTreehouseDispatchers.kt b/redwood-treehouse-host/src/iosMain/kotlin/app/cash/redwood/treehouse/IosTreehouseDispatchers.kt index 8e0f29c8aa..d400971e29 100644 --- a/redwood-treehouse-host/src/iosMain/kotlin/app/cash/redwood/treehouse/IosTreehouseDispatchers.kt +++ b/redwood-treehouse-host/src/iosMain/kotlin/app/cash/redwood/treehouse/IosTreehouseDispatchers.kt @@ -53,10 +53,8 @@ private class SingleThreadCoroutineDispatcher : CloseableCoroutineDispatcher() { /** * On Apple platforms we need to explicitly set the stack size for background threads; otherwise * we get the default of 512 KiB which isn't sufficient for our QuickJS programs. - * - * 8 MiB is more than sufficient. */ - private val stackSize = 8 * 1024 * 1024 + private val stackSize = ZIPLINE_THREAD_STACK_SIZE private val channel = Channel(capacity = Channel.UNLIMITED) val thread = NSThread {