@@ -71,36 +71,25 @@ globalThis.WebAssembly.instantiateStreaming = async function(m,i) {
7171} ;
7272
7373// Provide `setTimeout` for Kotlin coroutines.
74- // Deep in the Compose UI framework, one task is scheduled every 16ms, see
75- // https://github.com/JetBrains/compose-multiplatform-core/blob/a52f2981b9bc7cdba1d1fbe71654c4be448ebea7/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/spatial/RectManager.kt#L138
76- // and
77- // https://github.com/JetBrains/compose-multiplatform-core/blob/a52f2981b9bc7cdba1d1fbe71654c4be448ebea7/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/OnLayoutRectChangedModifier.kt#L56
78- // We don't want to delay work in the Wall-time based measurement in JetStream,
79- // but executing this immediately (without delay) produces redundant work that
80- // is not realistic for a full-browser Kotlin/multiplatform application either,
81- // according to Kotlin/JetBrains folks.
82- // Hence the early return for 16ms delays below.
83- // FIXME: The SpiderMonkey shell doesn't have `setTimeout` (yet). We could also
84- // polyfill this with `Promise.resolve().then(f)`, but that changes the CPU
85- // profile slightly on other engines, so it's probably best to just add support.
8674const originalSetTimeout = setTimeout ;
8775globalThis . setTimeout = function ( f , delayMs ) {
8876 // DEBUG
8977 // console.log('setTimeout', f, t);
9078
79+ // Deep in the Compose UI framework, one task is scheduled every 16ms, see
80+ // https://github.com/JetBrains/compose-multiplatform-core/blob/a52f2981b9bc7cdba1d1fbe71654c4be448ebea7/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/spatial/RectManager.kt#L138
81+ // and
82+ // https://github.com/JetBrains/compose-multiplatform-core/blob/a52f2981b9bc7cdba1d1fbe71654c4be448ebea7/compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/layout/OnLayoutRectChangedModifier.kt#L56
83+ // We don't want to delay work in the Wall-time based measurement in JetStream,
84+ // but executing this immediately (without delay) produces redundant work that
85+ // is not realistic for a full-browser Kotlin/multiplatform application either,
86+ // according to Kotlin/JetBrains folks.
87+ // Hence the early return for 16ms delays.
9188 if ( delayMs === 16 ) return ;
9289 if ( delayMs !== 0 ) {
9390 throw new Error ( 'Unexpected delay for setTimeout polyfill: ' + delayMs ) ;
9491 }
9592 originalSetTimeout ( f ) ;
96-
97- // Alternative, if setTimeout is not available in a shell (but that changes
98- // the performance profile a little bit, so I'd rather not do that):
99- // Promise.resolve().then(f);
100-
101- // Yet another alternative is to run the task synchronously, but that obviously
102- // overflows the stack at some point if the callback itself spawns more work:
103- // f();
10493}
10594
10695// Don't automatically run the main function on instantiation.
0 commit comments