Skip to content

Commit 60e51ff

Browse files
committed
Kotlin-compose: update to Compose 1.13.0-beta01 and Kotlin 2.4.20
Build the Compose Multiplatform benchmarks from upstream master (1574503571, which includes JetBrains/compose-multiplatform#5787 passing -Xwasm-use-new-exception-proposal to the Wasm linkTask) instead of the JetStream 3.0 hotfix branch (ok/jetstream3_hotfix, 84dad4d3f6), overriding compose.version to 1.13.0-beta01. This moves Kotlin from 2.2.20-Beta2 to 2.4.20 (stable), Compose from 1.8.2 to 1.13.0-beta01 (which includes the PR #3411 fix for per-frame JobCancellationException/Error stack allocation in RectManager and PR #3269/#3484 Skia wrapper reuse fixes), and Skiko from a custom 0.9.4.3 build to 0.156.0, while emitting standard WebAssembly exnref (try_table/throw_ref) with zero legacy try/catch instructions. Compiler option added in compiler-options.patch (both on compile and KotlinJsIrLink tasks): - -Xwasm-kclass-fqn=false: Works around KT-91066, where Kotlin 2.3+'s KClassImpl.hashCode() allocates and hashes "$packageName.$typeName" on every call (triggered on every Compose modifier node lookup). Removed workarounds: - The hotfix branch and its custom Skiko build. - use-beta-toolchain.patch: master uses a stable Kotlin (2.4.20). - jstag-workaround.patch: Safari's WebAssembly.JSTag fixes have shipped. - hook-print.patch: Kotlin's glue logs through console, and benchmark.js now silences console.log and console.warn unless verbose is set. - The skipFunMain global in benchmark.js, which nothing reads. Kept, rebased: empty-main-function.patch and skiko-disable-instantiate.patch (updated for Skiko 0.156.0's awaitSkikoCore). Also rewrite static imports in Kotlin 2.4's compose-benchmarks-benchmarks.import-object.mjs via sed in build.sh, instantiate compose-benchmarks-benchmarks.wasm directly in benchmark.js (replacing compose-benchmarks-benchmarks.uninstantiated.mjs), and disable window.caches in benchmark.js so Compose 1.12+'s ResourceWebCache uses the in-memory preload fetch polyfill in browsers just as in JS shells. TODOs once upstream updates ship: - Update CMP_REV to a newer compose-multiplatform commit once Compose 1.13.0 is stable (~mid-December 2026) and drop the explicit -Pcompose.version=1.13.0-beta01 override in build.sh. - Remove compiler-options.patch (-Xwasm-kclass-fqn=false) once KT-91066 is fixed and backported. Part of #277.
1 parent 5fb9b49 commit 60e51ff

15 files changed

Lines changed: 1763 additions & 9829 deletions

‎JetStreamDriver.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2564,7 +2564,7 @@ let BENCHMARKS = [
25642564
preload: {
25652565
skikoJsModule: "./workloads/Kotlin-compose-wasm/build/skiko.mjs",
25662566
skikoWasmBinary: "./workloads/Kotlin-compose-wasm/build/skiko.wasm",
2567-
composeJsModule: "./workloads/Kotlin-compose-wasm/build/compose-benchmarks-benchmarks.uninstantiated.mjs",
2567+
composeJsModule: "./workloads/Kotlin-compose-wasm/build/compose-benchmarks-benchmarks.import-object.mjs",
25682568
composeWasmBinary: "./workloads/Kotlin-compose-wasm/build/compose-benchmarks-benchmarks.wasm",
25692569
inputImageCompose: "./workloads/Kotlin-compose-wasm/build/compose-multiplatform.png",
25702570
inputImageCat: "./workloads/Kotlin-compose-wasm/build/example1_cat.jpg",

‎workloads/Kotlin-compose-wasm/benchmark.js‎

Lines changed: 97 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,22 @@ if (!globalThis.navigator.languages) {
1717
// Compose reads `window.isSecureContext` in its Clipboard feature:
1818
globalThis.isSecureContext = false;
1919

20+
// Disable the browser CacheStorage API (`window.caches`) so Compose 1.12+'s
21+
// `ResourceWebCache` reads preloaded resources directly from the in-memory
22+
// `fetch` polyfill below in browsers just as it does in JS shells.
23+
Object.defineProperty(globalThis, 'caches', { value: undefined, configurable: true });
24+
2025
// Disable explicit GC (it wouldn't work in browsers anyway).
2126
globalThis.gc = () => {
2227
// DEBUG
2328
// console.log("gc()");
2429
}
2530

31+
// `skiko.mjs` resolves `new URL("skiko.wasm", import.meta.url).href` before
32+
// setting `module.locateFile`. Override `URL` in both shells (where `URL` is
33+
// absent) and browsers (where `import.meta.url` is a `blob:` URL when
34+
// `prefetchResources` is enabled) so `findWasmBinary()` returns `"skiko.wasm"`
35+
// and hits the `preload` map below.
2636
class URL {
2737
href;
2838
constructor(url, base) {
@@ -33,6 +43,34 @@ class URL {
3343
}
3444
globalThis.URL = URL;
3545

46+
if (typeof globalThis.AbortController === 'undefined') {
47+
globalThis.AbortController = class {
48+
constructor() {
49+
this.signal = {};
50+
}
51+
abort() {}
52+
};
53+
}
54+
55+
class BlobPolyfill {
56+
constructor(uint8, type = '') {
57+
this._uint8 = uint8;
58+
this._type = type;
59+
}
60+
get size() {
61+
return this._uint8.byteLength;
62+
}
63+
get type() {
64+
return this._type;
65+
}
66+
async arrayBuffer() {
67+
return this._uint8.buffer;
68+
}
69+
slice(start = 0, end = this.size, type = this.type) {
70+
return new BlobPolyfill(this._uint8.slice(start, end), type);
71+
}
72+
}
73+
3674
// We always polyfill `fetch` and `instantiateStreaming` for consistency between
3775
// engine shells and browsers and to avoid introducing network latency into the
3876
// first iteration / instantiation measurement.
@@ -48,26 +86,31 @@ globalThis.fetch = async function(url) {
4886

4987
// Redirect some paths to cached/preloaded resources.
5088
if (preload[url]) {
89+
const buf = preload[url];
5190
return {
5291
ok: true,
5392
status: 200,
54-
arrayBuffer() { return preload[url]; },
93+
statusText: 'OK',
94+
arrayBuffer() { return buf; },
5595
async blob() {
56-
return {
57-
size: preload[url].byteLength,
58-
async arrayBuffer() { return preload[url]; }
59-
}
96+
return new BlobPolyfill(new Uint8Array(buf));
6097
},
6198
};
6299
}
63100

64101
// This should only be called in the browser, where fetch() is available.
65102
return originalFetch(url);
66103
};
67-
globalThis.WebAssembly.instantiateStreaming = async function(m,i) {
104+
globalThis.WebAssembly.instantiateStreaming = async function(m, i, options) {
68105
// DEBUG
69-
// console.log('instantiateStreaming',m,i);
70-
return WebAssembly.instantiate((await m).arrayBuffer(),i);
106+
// console.log('instantiateStreaming', m, i, options);
107+
const bytes = await (await m).arrayBuffer();
108+
if (options !== undefined) {
109+
const module = await WebAssembly.compile(bytes, options);
110+
const instance = await WebAssembly.instantiate(module, i);
111+
return { module, instance };
112+
}
113+
return WebAssembly.instantiate(bytes, i);
71114
};
72115

73116
// Provide `setTimeout` for Kotlin coroutines.
@@ -92,19 +135,37 @@ globalThis.setTimeout = function(f, delayMs) {
92135
originalSetTimeout(f);
93136
}
94137

95-
// Don't automatically run the main function on instantiation.
96-
globalThis.skipFunMain = true;
138+
// Compose 1.13 registers a `window.addEventListener('languagechange', ...)`
139+
// listener on scene initialization, and `kotlinx.coroutines` checks
140+
// `typeof window.addEventListener === 'function'` (`tryGetWindow`) to select
141+
// its browser `WindowMessageQueue` (`window.postMessage`) dispatcher.
142+
if (typeof globalThis.addEventListener === 'undefined') {
143+
const messageListeners = [];
144+
globalThis.addEventListener = function(type, listener) {
145+
if (type === 'message') {
146+
messageListeners.push(listener);
147+
}
148+
};
149+
globalThis.postMessage = function(data) {
150+
originalSetTimeout(() => {
151+
const event = { source: globalThis, data, stopPropagation() {} };
152+
for (const listener of messageListeners) {
153+
listener(event);
154+
}
155+
});
156+
};
157+
}
97158

98-
// Prevent this from being detected as a shell environment, so that we use the
99-
// same code paths as in the browser.
100-
// See `compose-benchmarks-benchmarks.uninstantiated.mjs`.
101-
delete globalThis.d8;
102-
delete globalThis.inIon;
103-
delete globalThis.jscOptions;
159+
// Suppress Kotlin's console output unless WasmEMCCBenchmark's verbose mode is
160+
// enabled, so benchmark iterations don't spam stdout/stderr.
161+
if (typeof verbose === 'undefined' || !verbose) {
162+
globalThis.console.log = () => {};
163+
globalThis.console.warn = () => {};
164+
}
104165

105166
class Benchmark {
106-
skikoInstantiate;
107-
mainInstantiate;
167+
skikoModule;
168+
composeImportObjectModule;
108169
wasmInstanceExports;
109170

110171
async init() {
@@ -124,8 +185,9 @@ class Benchmark {
124185
// We patched `skiko.mjs` to not immediately instantiate the `skiko.wasm`
125186
// module, so that we can move the dynamic JS import here but measure
126187
// WebAssembly compilation and instantiation as part of the first iteration.
127-
this.skikoInstantiate = (await JetStream.dynamicImport(JetStream.preload.skikoJsModule)).default;
128-
this.mainInstantiate = (await JetStream.dynamicImport(JetStream.preload.composeJsModule)).instantiate;
188+
this.skikoModule = await JetStream.dynamicImport(JetStream.preload.skikoJsModule);
189+
globalThis.kotlinWasmImports = { './skiko.mjs': this.skikoModule };
190+
this.composeImportObjectModule = await JetStream.dynamicImport(JetStream.preload.composeJsModule);
129191
}
130192

131193
async runIteration() {
@@ -134,8 +196,21 @@ class Benchmark {
134196

135197
// Compile once in the first iteration.
136198
if (!this.wasmInstanceExports) {
137-
const skikoExports = (await this.skikoInstantiate()).wasmExports;
138-
this.wasmInstanceExports = (await this.mainInstantiate({ './skiko.mjs': skikoExports })).exports;
199+
const skikoWasmExports = (await this.skikoModule.default()).wasmExports;
200+
const { importObject, setWasmExports } = this.composeImportObjectModule;
201+
// Replace `skiko.mjs`'s lazy JS wrapper thunks with the direct Wasm
202+
// exports from `skiko.wasm`, matching JetStream 3.0.
203+
importObject['./skiko.mjs'] = Object.assign({}, this.skikoModule, skikoWasmExports);
204+
205+
const wasmOptions = { builtins: ['js-string'], importedStringConstants: "'" };
206+
const { instance } = await WebAssembly.instantiateStreaming(
207+
fetch('./compose-benchmarks-benchmarks.wasm'),
208+
importObject,
209+
wasmOptions
210+
);
211+
setWasmExports(Object.assign({ memory: importObject.intrinsics.memory }, instance.exports));
212+
instance.exports._start();
213+
this.wasmInstanceExports = instance.exports;
139214
}
140215

141216
// We render/animate/process fewer frames than in the upstream benchmark,
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
Built on 2025-08-14 12:27:42+02:00
2-
Cloning into 'compose-multiplatform'...
3-
84dad4d3f6 Use custom skiko (0.9.4.3) to fix the FinalizationRegistry API usage for web targets
1+
Built on 2026-11-03T15:30:00Z
2+
1574503571 Benchmarks: pass -Xwasm-use-new-exception-proposal to Wasm linkTask (#5787)
3+
Toolchain versions (Skiko follows from Compose):
4+
kotlin = "2.4.20"
5+
compose-multiplatform = "1.12.1"
6+
compose.version override = "1.13.0-beta01" (Skiko 0.156.0)
47
Copying generated files into build/
58
Build success

‎workloads/Kotlin-compose-wasm/build.sh‎

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,50 @@ rm -rf build/
77
rm -rf compose-multiplatform/
88

99
BUILD_LOG="$(realpath build.log)"
10-
echo -e "Built on $(date --rfc-3339=seconds)" | tee "$BUILD_LOG"
10+
echo -e "Built on $(date -u '+%Y-%m-%dT%H:%M:%SZ')" | tee "$BUILD_LOG"
1111

1212
# Build the benchmark from source.
13-
# FIXME: Use main branch and remove hotfix patch below, once
14-
# https://youtrack.jetbrains.com/issue/SKIKO-1040 is resolved upstream.
15-
# See https://github.com/WebKit/JetStream/pull/84#discussion_r2252418900.
16-
git clone -b ok/jetstream3_hotfix https://github.com/JetBrains/compose-multiplatform.git |& tee -a "$BUILD_LOG"
13+
# TODO: Update CMP_REV to a newer compose-multiplatform commit once Compose
14+
# 1.13.0 is stable and drop the explicit -Pcompose.version=1.13.0-beta01
15+
# override below.
16+
CMP_REV="1574503571a25a3e71f71fef51962beefc494df6"
17+
CMP_VERSION_OVERRIDE="1.13.0-beta01"
18+
git clone -q https://github.com/JetBrains/compose-multiplatform.git 2>&1 | tee -a "$BUILD_LOG"
1719
pushd compose-multiplatform/
20+
git checkout -q "$CMP_REV" 2>&1 | tee -a "$BUILD_LOG"
1821
git log -1 --oneline | tee -a "$BUILD_LOG"
22+
echo "Toolchain versions (Skiko follows from Compose):" | tee -a "$BUILD_LOG"
23+
grep -E '^(kotlin|compose-multiplatform) = ' benchmarks/multiplatform/gradle/libs.versions.toml | tee -a "$BUILD_LOG"
24+
echo "compose.version override = \"$CMP_VERSION_OVERRIDE\" (Skiko 0.156.0)" | tee -a "$BUILD_LOG"
1925
# Do not read `isD8` in the main function which decides whether to run eagerly.
2026
# Instead, just patch that out statically.
2127
# TODO: Upstream that fix to the compose-multiplatform repo.
2228
git apply ../empty-main-function.patch | tee -a "$BUILD_LOG"
23-
# FIXME: Use stable 2.3 Kotlin/Wasm toolchain, once available around Sep 2025.
24-
git apply ../use-beta-toolchain.patch | tee -a "$BUILD_LOG"
29+
# Pass -Xwasm-kclass-fqn=false to the Kotlin/Wasm compile and link tasks.
30+
# TODO(https://youtrack.jetbrains.com/issue/KT-91066): Remove
31+
# compiler-options.patch once KT-91066 is fixed.
32+
git apply ../compiler-options.patch | tee -a "$BUILD_LOG"
2533
pushd benchmarks/multiplatform
26-
./gradlew :benchmarks:wasmJsProductionExecutableCompileSync
34+
./gradlew :benchmarks:wasmJsProductionExecutableCompileSync -Pcompose.version="$CMP_VERSION_OVERRIDE"
2735
# For building polyfills and JavaScript launcher to run in d8 (which inspires the benchmark.js launcher here):
28-
# ./gradlew :benchmarks:buildD8Distribution
36+
# ./gradlew :benchmarks:prepareWasmJsD8ProductionRuntime
2937
BUILD_SRC_DIR="compose-multiplatform/benchmarks/multiplatform/build/wasm/packages/compose-benchmarks-benchmarks/kotlin"
3038
popd
3139
popd
3240

3341
echo "Copying generated files into build/" | tee -a "$BUILD_LOG"
3442
mkdir -p build/ | tee -a "$BUILD_LOG"
35-
cp $BUILD_SRC_DIR/compose-benchmarks-benchmarks.{wasm,uninstantiated.mjs} build/ | tee -a "$BUILD_LOG"
36-
git apply hook-print.patch | tee -a "$BUILD_LOG"
37-
# FIXME: Remove once the JSC fixes around JSTag have landed in Safari, see
38-
# https://github.com/WebKit/JetStream/pull/84#issuecomment-3164672425.
39-
git apply jstag-workaround.patch | tee -a "$BUILD_LOG"
43+
cp $BUILD_SRC_DIR/compose-benchmarks-benchmarks.wasm build/ | tee -a "$BUILD_LOG"
44+
# Rewrite static ES module imports in the generated import-object module so it
45+
# can be loaded from a Blob URL in browsers and without unused dependencies in
46+
# JS shells (`@js-joda/core`, `.js-builtins.mjs`).
47+
sed -E "s|^import \* as ([A-Za-z0-9_$]+) from ('[^']+');$|const \1 = globalThis.kotlinWasmImports?.[\2] ?? {};|" \
48+
"$BUILD_SRC_DIR/compose-benchmarks-benchmarks.import-object.mjs" \
49+
> build/compose-benchmarks-benchmarks.import-object.mjs
50+
if grep -nE '^\s*import\s' build/compose-benchmarks-benchmarks.import-object.mjs; then
51+
echo "Error: unrewritten static import in compose-benchmarks-benchmarks.import-object.mjs" >&2
52+
exit 1
53+
fi
4054
cp $BUILD_SRC_DIR/skiko.{wasm,mjs} build/ | tee -a "$BUILD_LOG"
4155
git apply skiko-disable-instantiate.patch | tee -a "$BUILD_LOG"
4256
cp $BUILD_SRC_DIR/composeResources/compose_benchmarks.benchmarks.generated.resources/drawable/example1_cat.jpg build/ | tee -a "$BUILD_LOG"

0 commit comments

Comments
 (0)