diff --git a/js/web/web-backend.js b/js/web/web-backend.js index f540f987..94befe13 100644 --- a/js/web/web-backend.js +++ b/js/web/web-backend.js @@ -18,7 +18,9 @@ let init = wasm.default; let worker; async function initSnarkyJS() { - let { memory } = await init(); + const memory = allocateWasmMemoryForUserAgent(window.navigator.userAgent); + + await init(undefined, memory); let module = init.__wbindgen_wasm_module; let numWorkers = await getEfficientNumWorkers(); @@ -162,3 +164,21 @@ async function workerCall(worker, type, message) { worker.postMessage({ type, id, message }); return (await promise).result; } + +function allocateWasmMemoryForUserAgent(userAgent) { + const isIOSDevice = /iPad|iPhone|iPod/.test(userAgent); + const isSafari = /Safari/.test(userAgent); + if (isIOSDevice && isSafari) { + return new WebAssembly.Memory({ + initial: 19, + maximum: 16384, // 1 GiB + shared: true, + }); + } else { + return new WebAssembly.Memory({ + initial: 19, + maximum: 65536, // 4 GiB + shared: true, + }); + } +}