{"id":27993140,"url":"https://github.com/paralin/reuse-wasm-module-demo","last_synced_at":"2025-06-30T23:07:34.040Z","repository":{"id":285016888,"uuid":"952214694","full_name":"paralin/reuse-wasm-module-demo","owner":"paralin","description":"Demonstrate re-using the same compiled wasm module across workers with structured clone","archived":false,"fork":false,"pushed_at":"2025-03-20T23:25:48.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-27T09:15:37.820Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paralin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-20T23:15:37.000Z","updated_at":"2025-04-09T13:31:04.000Z","dependencies_parsed_at":"2025-03-28T23:48:40.436Z","dependency_job_id":"0bc3ec64-e989-4fb5-a533-c5c5fe3f64bc","html_url":"https://github.com/paralin/reuse-wasm-module-demo","commit_stats":null,"previous_names":["paralin/reuse-wasm-module-demo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/paralin/reuse-wasm-module-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paralin%2Freuse-wasm-module-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paralin%2Freuse-wasm-module-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paralin%2Freuse-wasm-module-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paralin%2Freuse-wasm-module-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paralin","download_url":"https://codeload.github.com/paralin/reuse-wasm-module-demo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paralin%2Freuse-wasm-module-demo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262864132,"owners_count":23376455,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-08T18:46:42.820Z","updated_at":"2025-06-30T23:07:34.032Z","avatar_url":"https://github.com/paralin.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebAssembly Module Reuse Demo\n\nThis project demonstrates how to compile a WebAssembly module once and reuse it across multiple web workers, avoiding redundant compilation.\n\n## What This Demonstrates\n\n1. **Single WebAssembly Compilation**: The main thread compiles the WebAssembly module once using `WebAssembly.compileStreaming()`.\n2. **Module Sharing**: The compiled module is shared with multiple web workers by sending the `WebAssembly.Module` object via `postMessage()`.\n3. **Independent Instantiation**: Each web worker independently instantiates the module, creating its own isolated execution environment.\n4. **Parallel Execution**: The same module is executed in parallel across different workers.\n\nThis approach offers several advantages:\n\n- Reduced memory usage by compiling the WebAssembly binary only once\n- Faster startup time for additional workers since compilation is skipped\n- Same code can be executed safely in parallel across multiple workers\n\n## Technologies Used\n\n- **AssemblyScript**: TypeScript-like language that compiles to WebAssembly\n- **Web Workers**: For parallel execution\n- **WebAssembly API**: Using the streaming compilation API for better performance\n- **Cross-Origin Isolation**: Enabled via COOP/COEP headers to support SharedArrayBuffer\n\n## Running the Demo\n\n1. Install dependencies:\n\n   ```\n   npm install\n   ```\n\n2. Build and run:\n\n   ```\n   npm run build\n   ```\n\n3. Open http://localhost:5173 in your browser\n\nThe demo will load a WebAssembly module containing two functions:\n\n- A simple \"Hello World\" string function\n- A Fibonacci calculation function\n\nThese functions will be executed in separate web workers to demonstrate parallel execution of the same module.\n\n## Implementation Details\n\nThe main thread:\n\n1. Fetches and compiles the WebAssembly module using `WebAssembly.compileStreaming()`\n2. Creates two web workers\n3. Posts the compiled module to both workers via `postMessage()`\n4. Sends execution commands to each worker\n\nEach worker:\n\n1. Receives the module reference\n2. Independently instantiates it with its own memory and execution context\n3. Executes functions from the module when requested\n4. Returns results to the main thread\n\nThis pattern can be extended to create worker pools that share the same WebAssembly module but execute in parallel.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparalin%2Freuse-wasm-module-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparalin%2Freuse-wasm-module-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparalin%2Freuse-wasm-module-demo/lists"}