google / starlark-go

Starlark in Go: the Starlark configuration language, implemented in Go
BSD 3-Clause "New" or "Revised" License
2.26k stars 204 forks source link

feat: show a demo that users can interact with using WASM #462

Open HarikrishnanBalagopal opened 1 year ago

HarikrishnanBalagopal commented 1 year ago

Feature Request

Overview

This library compiles nicely to WASM with just a small wrapper. It can be used to show a demo and/or for using this library in languages other than Golang. I have a working demo here https://haribala.dev/starlark-webasm-demo/ The code is here https://github.com/HarikrishnanBalagopal/starlark-webasm and here https://github.com/HarikrishnanBalagopal/starlark-webasm-demo

adonovan commented 1 year ago

This is really cool! I'm curious what the performance overhead is of compiling the interpreter from Go to wasm. Have you tried running any of the benchmarks in the starlark-go tree? (If Go's testing package is a challenge for wasm you could just run go test and observe how many iterations of each benchmark get run and then just rewrite the benchmarks as simple loops of a fixed count and see how long they take.

I imagine JavaScript programs would also want a slightly different API to the interpreter. Have you tried passing JavaScript values (and especially functions) in and out of Starlark programs?

laurentlb commented 1 year ago

Nice! I made something similar too: