@@ -71,36 +71,25 @@ globalThis.WebAssembly.instantiateStreaming = async function(m,i) {
71
71
} ;
72
72
73
73
// 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.
86
74
const originalSetTimeout = setTimeout ;
87
75
globalThis . setTimeout = function ( f , delayMs ) {
88
76
// DEBUG
89
77
// console.log('setTimeout', f, t);
90
78
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.
91
88
if ( delayMs === 16 ) return ;
92
89
if ( delayMs !== 0 ) {
93
90
throw new Error ( 'Unexpected delay for setTimeout polyfill: ' + delayMs ) ;
94
91
}
95
92
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();
104
93
}
105
94
106
95
// Don't automatically run the main function on instantiation.
0 commit comments