Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use WebAssembly.compileStreaming #267

Merged
merged 2 commits into from
Oct 29, 2023

Conversation

ledsun
Copy link
Contributor

@ledsun ledsun commented Aug 11, 2023

With WebAssembly.compileStreaming, compilation completes 40 ms faster than WebAssembly.compile.

Measurement Method

I subtracted the time it takes to download ruby+stdlib.wasm from the time it takes to compile ruby+stdlib.wasm and measured that as the difference between WebAssembly.compileStreaming and WebAssembly.compile.

Compile time

We added the following script to packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts and measured the time required to compile ruby+stdlib.wasm.

  const t0 = performance.now();

  const response = fetch(
    `https://cdn.jsdelivr.net/npm/${pkg.name}@${pkg.version}/dist/ruby+stdlib.wasm`,
  );

  // Switch comments for each measurement target.
  const module = await WebAssembly.compileStreaming(response);
  // const buffer = await response.then((res) => res.arrayBuffer());
  // const module = await WebAssembly.compile(buffer);

  const t1 = performance.now();
  console.log(`Compiling ruby+stdlib.wasm to took ${t1 - t0} milliseconds.`);

Download time

The time taken to download ruby+stdlib.wasm was obtained from the network tab of Google Chrome.
For example:

image

Cache has been disabled.

Measurement Results

WebAssembly.complieStreaming

Average 21 ms

No. Compile time(ms) Download time(ms) diff(ms)
1 463 443 20
2 387 364 22
3 479 458 21

WebAssembly.complie

Average 62.7 ms

No. Compile time(ms) Download time(ms) diff(ms)
1 485 425 60
2 447 383 64
3 512 448 64

With WebAssembly.compileStreaming, compilation completes 40 ms faster than WebAssembly.compile.
Since WebAssembly.compileStreaming is not available in iOS Safari 14
@kateinoigakukun kateinoigakukun enabled auto-merge (rebase) October 29, 2023 06:07
@kateinoigakukun kateinoigakukun merged commit c4c5083 into ruby:main Oct 29, 2023
31 checks passed
@ledsun ledsun deleted the web_assembly_compile_streaming branch December 3, 2023 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants