Hacker News new | ask | show | jobs
by spankalee 59 days ago
Rust is better at targeting WebAssembly
2 comments

why would that be important? Having a typescript compiler in wasm seems like a pretty niche need.
It's extremely useful if your distribution platform is the web. However, I find it much more valuable as a type checker than a compiler. I use TypeScript extensively (in several projects) for defining schemas types.

For example, in the Breaka Club (https://breaka.club/) editor, which is not presently exposed to kids yet, we define behaviors for characters, props, mosaics (terrain tiles) and items in JSON. But the JSON has type checking and real-time completion as you type. Not naive property auto-suggestion, we have effect types and they're context aware in that you can refer to targets introduced higher in parent constructs of the JSON — and they're fully type checked. If you refer to a target that does not exist in a context, it won't validate and you cannot save the schema.

We use tsgo for development, but the editor (runtime schema validation) is presently stuck on TypeScript 6 because there's no WASM support.

Now, is it nutty that we're using TypeScript for JSON validation? A little. But it's extremely powerful. We're going far beyond what's capable with Zod or ArkType.

Because you need to keep the compiler running here,

- https://www.typescriptlang.org

- https://code.visualstudio.com/docs/remote/vscode-web

Theo is making a new twist on the idea of IDE which hosts the application itself. I'm sure there's going to be a video about it soon. But the idea is to embed the whole compilation and type-check in wasm in the browser which then runs the app immediately, as the agents edit the code.
But it's not the only niche, see Typst compiler in wasm for live document generation in the browser.
Why?
I'm assuming they mean because it doesn't need a garbage collector or much of a runtime at all. You can target direct to WASM and use I guess WASI, while Go brings with it a garbage collector and so on.
Wasm is a first-class target for Rust, which produces faster and smaller Wasm binaries. My understanding is that you need to use TinyGo to reasonably target Wasm with Go.

Go having a garbage collector isn't necessarily bad, since Wasm has GC, but I think Go's GC can't easily use Wasm GC because Go has interior pointers.

WASM is also a first-class target for Go (gc).

However, it has a relatively large runtime, so TinyGo is often preferred when bundle size needs to be small.

With the caveat that Go cannot use WASM GC, because it is still a MVP and it does not support internal pointers, so languages like D, Go and C# have to keep shipping their own implementations.
I think the main advantage is size. Rust doesn't need to include the runtime.