Skip to content

jocelin/wasm-game-of-life

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wasm Game of Life

This project explores rust and webassembly following Rust and WebAssembly Tutorial

Prerequisites:

Tools:

  • Rust
    • core:
      • rustup, rustrc, cargo
    • ecosystem:
      • wasm-pack: convert rust to WebAssembly to JavaScript
      • cargo-generate (optional)
      • npm init template create-wasm-app
  • npm & nodejs

Development

  • Workflow:
    • Rust > WebAssembly > JavaScript
      1. build rust project into WebAssembly and JavaScript: wasm-pack build
      2. run the app from within app with normal npm commands
  • Key Concepts in development (notes from tutorial):
    • interfacing Rust and JavaScript

      1. Minimizing copying into and out of the WebAssembly linear memory. Unnecessary copies impose unnecessary overhead.
      2. Minimizing serializing and deserializing. Similar to copies, serializing and deserializing also imposes overhead, and often imposes copying as well. If we can pass opaque handles to a data structure — instead of serializing it on one side, copying it into some known location in the WebAssembly linear memory, and deserializing on the other side — we can often reduce a lot of overhead. wasm_bindgen helps us define and work with opaque handles to JavaScript Objects or boxed Rust structures.

      As a general rule of thumb: a good JavaScript↔WebAssembly interface design is often one where large, long-lived data structures are implemented as Rust types that live in the WebAssembly linear memory, and are exposed to JavaScript as opaque handles.

      JavaScript calls exported WebAssembly functions that take these opaque handles, transform their data, perform heavy computations, query the data, and ultimately return a small, copy-able result.

      By only returning the small result of the computation, we avoid copying and/or serializing everything back and forth between the JavaScript garbage-collected heap and the WebAssembly linear memory.

Credits

The project is generated using the following templates:

🔋 Batteries Included

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE_APACHE
MIT
LICENSE_MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published