{"id":15393939,"url":"https://github.com/inkeliz/go_inkwasm","last_synced_at":"2025-04-14T03:34:07.465Z","repository":{"id":57657718,"uuid":"462012901","full_name":"inkeliz/go_inkwasm","owner":"inkeliz","description":"Faster alternative to `syscall/js`. Code-generated Javascript and Assembly, up to 2x faster than native syscall/js.","archived":false,"fork":false,"pushed_at":"2024-05-19T17:40:17.000Z","size":74,"stargazers_count":33,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T17:36:36.867Z","etag":null,"topics":["go","golang","syscall","wasm","webassembly"],"latest_commit_sha":null,"homepage":"","language":"Go","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/inkeliz.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":"2022-02-21T20:00:52.000Z","updated_at":"2024-09-28T16:12:01.000Z","dependencies_parsed_at":"2024-06-19T00:24:13.407Z","dependency_job_id":"81da6eaa-132c-45ea-845f-bc6ae9864671","html_url":"https://github.com/inkeliz/go_inkwasm","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inkeliz%2Fgo_inkwasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inkeliz%2Fgo_inkwasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inkeliz%2Fgo_inkwasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inkeliz%2Fgo_inkwasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inkeliz","download_url":"https://codeload.github.com/inkeliz/go_inkwasm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248815792,"owners_count":21165982,"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":["go","golang","syscall","wasm","webassembly"],"created_at":"2024-10-01T15:20:59.525Z","updated_at":"2025-04-14T03:34:07.448Z","avatar_url":"https://github.com/inkeliz.png","language":"Go","readme":"# Golang InkWasm\n\n\n**InkWasm** is faster `syscall/js` replacement, it's a package and a generator. Our goal is to be as faster and avoid unnecessary allocations. **InkWasm** initially created for [Gio](https://gioui.org/), improving the performance for [WebGL API](https://developer.mozilla.org/pt-BR/docs/Web/API/WebGL_API), in some devices and tests **InkWasm** is 2x faster than `syscall/js`, in real application it's 1.6x faster.\n\n\u003e ⚠️ The generator changes the file of the current packages and imported packages. It is still experimental, keep a backup file and use some versioning tool (like Git). \n\n## Golang Version\n\n\u003e Go 1.20+: Current main branch\n\u003e \n\u003e Go 1.18~Go1.20: https://github.com/inkeliz/go_inkwasm/releases/tag/v0.1.20\n\n## Benchmark\n\nThe performance may vary based on how you use `syscall/js` and **InkWasm**. Look into `inkwasm/tests_js_test.go` for more details.\n\n```\nBenchmark_DOM_INKWASM                       50000        11462 ns/op         52 B/op         1 allocs/op\nBenchmark_DOM_RUNTIME_INKWASM               50000        14934 ns/op        100 B/op         4 allocs/op\nBenchmark_DOM_BAD_RUNTIME_INKWASM           50000        18302 ns/op        100 B/op         4 allocs/op\nBenchmark_DOM_JS_SYSCALL                    50000        23550 ns/op        167 B/op        11 allocs/op\nBenchmark_DOM_BAD_JS_SYSCALL                50000        30540 ns/op        175 B/op        12 allocs/op\n\nBenchmark_BytesRandom_INKWASM              100000         1026 ns/op          0 B/op         0 allocs/op\nBenchmark_BytesRandom_JS_SYSCALL           100000         1808 ns/op         40 B/op         3 allocs/op\n\nBenchmark_SetLocalStorage_INKWASM          854655         6312 ns/op          0 B/op         0 allocs/op\nBenchmark_SetLocalStorage_JS_SYSCALL       486326        11796 ns/op         64 B/op         4 allocs/op\n\nBenchmark_GetLocalStorage_INKWASM         1830148         3300 ns/op          4 B/op         1 allocs/op\nBenchmark_GetLocalStorage_JS_SYSCALL       826088         7356 ns/op         48 B/op         6 allocs/op\n\nBenchmark_GetLocationHostname_JS_SYSCALL  3038510         1979 ns/op         32 B/op         2 allocs/op\nBenchmark_GetLocationHostname_INKWASM     2499522         2442 ns/op         16 B/op         1 allocs/op\n```\n\nCurrently, **InkWasm** is used in one fork of Gio, **you can test it online here**.\n\n|                              | Chrome 98 @ Ryzen 3900X | Chrome 98 @ Xiaomi Note 9 | Safari 15 @ MacBook Air |\n|-------------------------------------|------------------|-----------------|----------------|\n| gioui.org@bed59024                  | ~4.65ms          | ~31.91ms         | ~5.58ms        |\n| github.com/inkeliz/gio@main_inkjs   | ~3.02ms          | ~20.03ms         | ~4.84ms        |\n\nThe performance improvement varies from 13% up to 37%. [You can test it online, and compare the performance on your machine](https://gio-bench.pages.dev/). Want to know how it was implemented? [Check it here](https://github.com/Inkeliz/gio/commit/baf7d943e5d50debf354d4cd5f951d442d4d9b4e).\n\n## Usage\n\nIn order to use the generator, you must create one `func` without body and describe what is the JS function (or attribute) that imports the function.\n\n```\nfunc main() {\n    alert(\"Your String\")\n}\n\n//inkwasm:func globalThis.alert\nfunc alert(s string)\n```\n\nYou should run: `go run github.com/inkeliz/go_inkwasm build .`. It will create a new `wasm-build` folder, you can run `npx serve ./wasm-build` and run it on browser.\n\nThe generator is faster, but you can also use the `inkwasm` on \"runtime\", similar to `syscall/js`:\n\n```\nfunc main() {\n    alert := inkwasm.Global().Get(\"alert\")\n    defer alert.Free()\n\n    alert.Invoke(\"Text\")\n}\n```\n\nUsually, it still faster than `syscall/js` and have less allocations.\n\n-----------\n\n#### Calling static functions:\n\nYou can invoke functions that are \"hardcoded\", for instance `alert`:\n```\n//inkwasm:func globalThis.alert\nfunc alert(s string)\n```\n```\nfunc main() {\n    alert(\"Text\")\n}\n```\n\nIt will call `globalThis.alert`.\n\n### Calling dynamic functions:\n\nYou can also call functions that belongs to a specific Object, the name must start with `.`:\n\n```\n//inkwasm:func .bufferData\nfunc glBufferData(o inkwasm.Object, data []byte, usage uint)\n```\n```\nfunc main() {\n    ///... \n    glBufferData(gl, data, STATIC_DRAW)\n}\n```\n\nIt will call `o.bufferData` (is expected that the given `o`, `inkwasm.Object`, is a WebGL Context).\n\n### Get attribute:\n\nIn order to get a attribute use `inkwasm:get`:\n\n```\n//inkwasm:get globalThis.location.hostname\nfunc getHostname() string\n```\n\n#### Set attribute:\n\nIn order to set attribute use `inkwasm:set`:\n\n```\n//inkwasm:set .innerHTML\nfunc setInnerHTML(o inkwasm.Object, v string)\n```\n\n## Roadmap\n\nCurrently, **InkWasm** is very experimental and WebAssembly, in general, is also very experimental.\n\n- [x] Calling JS functions (`inkwasm:func`)\n- [x] Get JS property (`inkwasm:get`)\n- [x] Set JS property (`inkwasm:set`)\n\n- [x] Support integers input (`uint`, `int`, `int64`, ...)\n- [x] Support integers output (`uint`, `int`, `int64`, ...)\n- [x] Support floats input (`float64`, `float32`)\n- [x] Support floats output (`float64`, `float32`)\n- [x] Support slices/array input (`string`, `[]byte`, `[]float64`, `[10]byte`, ...)\n- [x] Support slices/array output (`string`, `[]byte`, `[]float64`, `[10]byte`, ...)\n- [x] Support big integers input (`big.Int`)\n- [ ] Support big integers output (`big.Int`)\n- [ ] Support channels input (`chan string`, ...)\n- [ ] Support channels output (`chan string`, ...)\n- [ ] Support complex input (`complex64`, `complex128`)\n- [ ] Support complex output (`complex64`, `complex128`)\n- [ ] Support functions input (`func(){}`)\n\n- [ ] Support TinyGo\n\n- [~] Export struct (`inkwasm:export`)\n- [ ] Export functions (`inkwasm:export`)\n- [ ] Export alias type (`inkwasm:export`)\n- [ ] Exported functions without `js.FuncOf`\n\n- [x] Import custom scripts (`*_js.js`) into `wasm.js`.\n- [ ] Use `-overlay` on `cmd/go`.\n\n- [ ] Improve tests\n\n## Blockers\n\n- ~~`CallImport` will be removed:~~\n\n  ~~Currently, **InkWasm** heavily rely on `CallImport`, it will be removed in the future and will be exclusive to `syscall/js` and `runtime` [golang#38248](https://github.com/golang/go/issues/38248). If that happens, the only solution is to replace `syscall/js`, maybe using `-overlay` on `cmd/go`.~~\n\n- `go:wasmexport` isn't (yet) supported:\n\n  Currently, the only way to export function is using `syscall/js`. However, that is quite slow. We can hack into `runtime` and `syscall/js` to be able to replace `js.FuncOf`. However, I'm waiting to see the progress of the proposal ([golang#42372](https://github.com/golang/go/issues/42372)). \n\n\n## Compatibility\n\nThe current API is supposed to be backward compatible with any future update. However, the **InkWasm** may not work on older versions of Golang and the idea is to be compatible with the latest golang version.\n\n## Contributing\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n[MIT](https://choosealicense.com/licenses/mit/)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finkeliz%2Fgo_inkwasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finkeliz%2Fgo_inkwasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finkeliz%2Fgo_inkwasm/lists"}