@@ -38,24 +38,31 @@ globalThis.URL = URL;
38
38
// first iteration / instantiation measurement.
39
39
// The downside is that this doesn't test streaming Wasm instantiation, which we
40
40
// are willing to accept.
41
- let preload = { } ;
41
+ let preload = { /* Initialized in init() below due to async. */ } ;
42
+ const originalFetch = globalThis . fetch ?? function ( url ) {
43
+ throw new Error ( "no fetch available" ) ;
44
+ }
42
45
globalThis . fetch = async function ( url ) {
43
46
// DEBUG
44
47
// console.log('fetch', url);
45
- if ( ! preload [ url ] ) {
46
- throw new Error ( 'Unexpected fetch: ' + url ) ;
48
+
49
+ // Redirect some paths to cached/preloaded resources.
50
+ if ( preload [ url ] ) {
51
+ return {
52
+ ok : true ,
53
+ status : 200 ,
54
+ arrayBuffer ( ) { return preload [ url ] ; } ,
55
+ async blob ( ) {
56
+ return {
57
+ size : preload [ url ] . byteLength ,
58
+ async arrayBuffer ( ) { return preload [ url ] ; }
59
+ }
60
+ } ,
61
+ } ;
47
62
}
48
- return {
49
- ok : true ,
50
- status : 200 ,
51
- arrayBuffer ( ) { return preload [ url ] ; } ,
52
- async blob ( ) {
53
- return {
54
- size : preload [ url ] . byteLength ,
55
- async arrayBuffer ( ) { return preload [ url ] ; }
56
- }
57
- } ,
58
- } ;
63
+
64
+ // This should only be called in the browser, where fetch() is available.
65
+ return originalFetch ( url ) ;
59
66
} ;
60
67
globalThis . WebAssembly . instantiateStreaming = async function ( m , i ) {
61
68
// DEBUG
@@ -116,8 +123,8 @@ class Benchmark {
116
123
// console.log("init");
117
124
118
125
preload = {
119
- 'skiko.wasm' : await getBinary ( wasmSkikoBinary ) ,
120
- './compose-benchmarks-benchmarks.wasm' : await getBinary ( wasmBinary ) ,
126
+ 'skiko.wasm' : await getBinary ( skikoWasmBinary ) ,
127
+ './compose-benchmarks-benchmarks.wasm' : await getBinary ( composeWasmBinary ) ,
121
128
'./composeResources/compose_benchmarks.benchmarks.generated.resources/drawable/compose-multiplatform.png' : await getBinary ( inputImageCompose ) ,
122
129
'./composeResources/compose_benchmarks.benchmarks.generated.resources/drawable/example1_cat.jpg' : await getBinary ( inputImageCat ) ,
123
130
'./composeResources/compose_benchmarks.benchmarks.generated.resources/files/example1_compose-community-primary.png' : await getBinary ( inputImageComposeCommunity ) ,
@@ -128,8 +135,8 @@ class Benchmark {
128
135
// We patched `skiko.mjs` to not immediately instantiate the `skiko.wasm`
129
136
// module, so that we can move the dynamic JS import here but measure
130
137
// WebAssembly compilation and instantiation as part of the first iteration.
131
- this . skikoInstantiate = ( await dynamicImport ( 'Kotlin-compose/build/skiko.mjs' ) ) . default ;
132
- this . mainInstantiate = ( await dynamicImport ( 'Kotlin-compose/build/compose-benchmarks-benchmarks.uninstantiated.mjs' ) ) . instantiate ;
138
+ this . skikoInstantiate = ( await dynamicImport ( skikoJsModule ) ) . default ;
139
+ this . mainInstantiate = ( await dynamicImport ( composeJsModule ) ) . instantiate ;
133
140
}
134
141
135
142
async runIteration ( ) {
0 commit comments