{"id":21547581,"url":"https://github.com/zabackary/scratch-vm-wasm-runtime","last_synced_at":"2025-08-25T03:37:33.720Z","repository":{"id":205073933,"uuid":"680722357","full_name":"zabackary/scratch-vm-wasm-runtime","owner":"zabackary","description":"A simple better Rust WASM VM for scratch-vm","archived":false,"fork":false,"pushed_at":"2024-02-03T08:34:55.000Z","size":55,"stargazers_count":8,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-24T07:07:15.302Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zabackary.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE_APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-20T07:16:12.000Z","updated_at":"2024-10-17T22:50:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"1d33469f-8ded-4894-99cb-a0de05539c50","html_url":"https://github.com/zabackary/scratch-vm-wasm-runtime","commit_stats":null,"previous_names":["zabackary/scratch-vm-wasm-runtime"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zabackary%2Fscratch-vm-wasm-runtime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zabackary%2Fscratch-vm-wasm-runtime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zabackary%2Fscratch-vm-wasm-runtime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zabackary%2Fscratch-vm-wasm-runtime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zabackary","download_url":"https://codeload.github.com/zabackary/scratch-vm-wasm-runtime/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248166927,"owners_count":21058480,"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":"2024-11-24T06:15:35.963Z","updated_at":"2025-04-10T05:53:08.481Z","avatar_url":"https://github.com/zabackary.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `scratch-wm-wasm-runtime`\n\n\u003e Basically just a loop that runs bytecode instructions.\n\nFor an explainer, please see [this documentation](./docs/bytecode-schematics.md), which explains the format of the bytecode.\n\nCode outline:\n\n* `lib.rs` just binds the JS and the Rust code using `wasm-pack` and `wasm-bindgen`\n* `runner.rs` just iterates over the list of instructions and runs them\n* `execute_instruction.rs` executes individual instructions using a big `match` tree\n* `instruction.rs` contains definitions for the instructions and the `struct` for their representation\n* `scratch_value.rs` contains operations that act on Scratch-like polymorphic values.\n\nThe entire thing is a stack-based interpreter.\n\n## Update about this project, in case you're interested:\n\nI worked on this project for a little while in Summer 2023, and after getting a working prototype, it turned out that\nhaving the overhead of a VM meant that there was not very much savings, and TurboWarp's compiled code was ~2x faster.\nThis could be because internally, the V8 JS engine (at least on Chrome) already compiles JS to machine code, and while\nWASM is faster than JS because it can be optimized better even if it still needs JIT compilation, running a VM there and\nrunning yet another layer of bytecode isn't very fast. If you want to optimize things to make it faster in the hopes\nthat it might pass TurboWarp, go ahead and submit a PR!\n\nFor future work (that I don't have time for, being a student and working on other projects), it might be possible to JIT\ncompile TurboWarp's Scratch AST (which is different from `scratch-vm`'s in that it's meant to be compiled) to actual\nWebAssembly much like [v86](https://github.com/copy/v86#:~:text=Machine%20code%20is%20translated%20to%20WebAssembly%20modules%20at%20runtime%20in%20order%20to%20achieve%20decent%20performance.)\ncompiles x86 machine code to WASM bytecode. If you do this, please let me know! I'm curious to see whether it works.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzabackary%2Fscratch-vm-wasm-runtime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzabackary%2Fscratch-vm-wasm-runtime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzabackary%2Fscratch-vm-wasm-runtime/lists"}