nodejs / nodejs/node

WebAssembly compiled module cache

オープン
#36,671 コメント 28 件 リアクション 10 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

feature request never-stale wasm
主要言語
JavaScript
スター
122k
フォーク
37.3k
平均マージ
4日 2時間
マージ済み PR(30日)
283

説明

Is your feature request related to a problem? Please describe.

Large WASM modules take a while to compile, impacting startup times. Browsers solve this problem by caching compiled module data.

WebAssembly is a promising media for software distribution. It makes sense to compile for WebAssembly once, instead of shipping multiple binaries for each supported CPU architecture / OS pair, doesn't it? There's a growing number of tools targeting this particular segment, e.g. https://wasmer.io.

Node.js has unique advantages as a WASM runner:

  • WASI as a standardised interface for interfacing with the OS (e.g. accessing files, etc.) is insufficient for most practical needs. With Node, one can leverage a plethora of high quality battle-tested cross platform libraries.

  • V8 is top notch! It beats competing WASM engines in terms of compile times, resource consumption and the footprint of compiled WASM files (a single data point: V8 produces 160MiB for a 50MiB WASM file, a competitor generates 1+GiB).

  • NPM is super robust. Competitors have their own package managers but not particularly reliable ones.

The only component missing in Node.js is a compiled module cache.

It takes 47s to compile the previously mentioned 50MiB WASM file. With a cache POC, the startup time is reduced to under 1s.

Describe the solution you'd like

require('wasm/cache').loadFile('module.wasm')

as a cache-enabled moral equivalent of

WebAssembly.compile(require('fs').readFileSync('module.wasm'))

Cache files to be stored in OS-mandated cache directory, e.g. ~/.cache/node/wasm-cache on Linux.

Describe alternatives you've considered

It used to be possible to serialise a WebAssembly module to a file explicitly. #18265

It stopped working since Node.js 13 due to changes in V8 and there's no way to make it work again.

Instead of introducing a new API, it is possible to enhance WebAssembly.compile/WebAssembly.compileStreaming. Unfortunately, it's hard to come up with a good cache key. We could sha256 the data, but that's inefficient.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

この issue では実装ファイルもテストも指定されていません。まず WebAssembly.compile と WebAssembly.compileStreaming のエントリーポイント、および #18265 のシリアライズ履歴を調べてください。完了の条件は、キャッシュキーに関する懸念と提案されている API の形に対処しつつ、OS のキャッシュディレクトリから module.wasm を読み込める、サポート対象のコンパイル済みモジュールキャッシュを実装することです。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, node.js, wasm
領域
backend, performance
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。