nodejs / nodejs/node

WebAssembly compiled module cache

Abierto
#36,671 28 comentarios 10 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

feature request never-stale wasm
Lenguaje dominante
JavaScript
Estrellas
122k
Forks
37.3k
Merge medio
4 d 2 h
PR fusionados (30 d)
283

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

El issue no menciona archivos de implementación ni pruebas; empieza examinando los puntos de entrada WebAssembly.compile y WebAssembly.compileStreaming y el historial de serialización en #18265. Se considera terminado cuando exista compatibilidad con una caché de módulos compilados que pueda cargar module.wasm desde un directorio de caché del sistema operativo, abordando las cuestiones relacionadas con las claves de caché y la forma de API propuesta.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript, node.js, wasm
Área
backend, performance
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.