diff --git a/core/wasm/README.md b/core/wasm/README.md index b55f449e..ee34d006 100644 --- a/core/wasm/README.md +++ b/core/wasm/README.md @@ -1,12 +1,13 @@ # noVNC + wasm -The following example is based on this tutorial: +This is a WebAssembly proof-of-concept. -https://hacks.mozilla.org/2018/04/javascript-to-rust-and-back-again-a-wasm-bindgen-tale/ +It is based on information from the following sources: -and this example: - -https://github.com/rustwasm/wasm-bindgen/blob/master/examples/julia\_set/ +* https://hacks.mozilla.org/2018/04/javascript-to-rust-and-back-again-a-wasm-bindgen-tale/ +* https://www.hellorust.com/demos/canvas/index.html +* https://github.com/rustwasm/wasm-bindgen/blob/master/examples/julia\_set/ +* https://github.com/rustwasm/wasm\_game\_of\_life/ ## Prep: @@ -19,10 +20,27 @@ docker run -it -v `pwd`:/novnc -w /novnc/core/wasm -p 8080:8080 rust-wasm bash npm install ``` -Build: +## Build: ``` -cargo +nightly build --target wasm32-unknown-unknown -wasm-bindgen target/wasm32-unknown-unknown/debug/novnc.wasm --out-dir . -npm run serve # then visit localhost:8080 outside the container +npm run build-release # or run build-debug (10x slower code) +npm run serve # then visit localhost:8080 outside the container ``` + +Note that `run server` will automatically detect modification to +`index.js` and reload the page. + + +## Preliminary results: + +* 2048x1024, draw1, release: 66.7ms +* 2048x1024, draw2, release: 34.1ms ( 21.7ms / 12.4ms) +* 2048x1024, draw3, release: 29.9ms ( 15.1ms / 14.8ms) + +* 1024x1024, draw1, release: 47.5ms +* 1024x1024, draw2, release: 21.8ms ( 12.0ms / 9.8ms) +* 1024x1024, draw3, release: 16.7ms ( 6.9ms / 9.8ms) + +* 1024x1024, draw1, debug: 376.6ms +* 1024x1024, draw2, debug: 132.4ms (129.1ms / 3.3ms) +* 1024x1024, draw3, debug: 131.4ms (128.8ms / 2.6ms) diff --git a/core/wasm/bootstrap.js b/core/wasm/bootstrap.js new file mode 100644 index 00000000..555057d4 --- /dev/null +++ b/core/wasm/bootstrap.js @@ -0,0 +1,11 @@ +// Currently WebAssembly modules cannot be synchronously imported in the main +// chunk: https://github.com/webpack/webpack/issues/6615 +// +// By dynamically importing index.js webpack will split it into a separate chunk +// automatically, where synchronous imports of WebAssembly is allowed. + +const index = import("./index"); +index.then(() => { + console.log("Loaded..."); +}); + diff --git a/core/wasm/index.html b/core/wasm/index.html index e4f4ce04..3d5703f0 100644 --- a/core/wasm/index.html +++ b/core/wasm/index.html @@ -3,7 +3,7 @@
- - + +