From 0b3ab52a8e09da784467da111514ffbef9e8a8ed Mon Sep 17 00:00:00 2001 From: ledsun Date: Fri, 11 Aug 2023 14:25:04 +0900 Subject: [PATCH] Use WebAssembly.compileStreaming With WebAssembly.compileStreaming, compilation completes 40 ms faster than WebAssembly.compile. --- packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts b/packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts index 7a9048ab9d..9cce69a8f7 100644 --- a/packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts +++ b/packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts @@ -1,11 +1,10 @@ import { DefaultRubyVM } from "./browser"; export const main = async (pkg: { name: string; version: string }) => { - const response = await fetch( + const response = fetch( `https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`, ); - const buffer = await response.arrayBuffer(); - const module = await WebAssembly.compile(buffer); + const module = await WebAssembly.compileStreaming(response); const { vm } = await DefaultRubyVM(module); vm.printVersion();